home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60src.lha / Vim / vim60 / src / option.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-26  |  213.7 KB  |  8,576 lines

  1. /* vi:set ts=8 sts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved    by Bram Moolenaar
  4.  *
  5.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  6.  * Do ":help credits" in Vim to see a list of people who contributed.
  7.  * See README.txt for an overview of the Vim source code.
  8.  */
  9.  
  10. /*
  11.  * Code to handle user-settable options. This is all pretty much table-
  12.  * driven. Checklist for adding a new option:
  13.  * - Put it in the options array below (copy an existing entry).
  14.  * - For a global option: Add a variable for it in option.h.
  15.  * - For a buffer or window local option:
  16.  *   - Add a PV_XX entry to the enum below.
  17.  *   - Add a variable to the window or buffer struct in structs.h.
  18.  *   - For a window option, add some code to copy_winopt().
  19.  *   - For a buffer option, add some code to buf_copy_options().
  20.  *   - For a buffer string option, add code to check_buf_options().
  21.  * - If it's a numeric option, add any necessary bounds checks to do_set().
  22.  * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
  23.  * - When adding an option with expansion (P_EXPAND), but with a different
  24.  *   default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
  25.  * - Add documentation!  One line in doc/help.txt, full description in
  26.  *   options.txt, and any other related places.
  27.  * - Add an entry in runtime/optwin.vim.
  28.  * When making changes:
  29.  * - Adjust the help for the option in doc/option.txt.
  30.  * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
  31.  *   comment at the help for the 'compatible' option.
  32.  */
  33.  
  34. #define IN_OPTION_C
  35. #include "vim.h"
  36.  
  37. /*
  38.  * The options that are local to a window or buffer have "indir" set to one of
  39.  * these values.  Special values:
  40.  * PV_NONE: global option.
  41.  * PV_BOTH is added: global option which also has a local value.
  42.  */
  43. #define PV_BOTH 0x1000
  44. #define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
  45.  
  46. typedef enum
  47. {
  48.     PV_NONE = 0
  49.     , PV_AI
  50.     , PV_AR
  51.     , PV_BH
  52.     , PV_BIN
  53.     , PV_BL
  54.     , PV_BOMB
  55.     , PV_BT
  56.     , PV_CIN
  57.     , PV_CINK
  58.     , PV_CINO
  59.     , PV_CINW
  60.     , PV_CMS
  61.     , PV_COM
  62.     , PV_CPT
  63.     , PV_DEF
  64.     , PV_DICT
  65.     , PV_DIFF
  66.     , PV_EFM
  67.     , PV_EOL
  68.     , PV_EP
  69.     , PV_ET
  70.     , PV_FDC
  71.     , PV_FDE
  72.     , PV_FDI
  73.     , PV_FDL
  74.     , PV_FDM
  75.     , PV_FDN
  76.     , PV_FDT
  77.     , PV_FEN
  78.     , PV_FENC
  79.     , PV_FF
  80.     , PV_FML
  81.     , PV_FMR
  82.     , PV_FO
  83.     , PV_FT
  84.     , PV_GP
  85.     , PV_IMI
  86.     , PV_IMS
  87.     , PV_INC
  88.     , PV_INDE
  89.     , PV_INDK
  90.     , PV_INEX
  91.     , PV_INF
  92.     , PV_ISK
  93.     , PV_KEY
  94.     , PV_KMAP
  95.     , PV_LBR
  96.     , PV_LISP
  97.     , PV_LIST
  98.     , PV_MA
  99.     , PV_ML
  100.     , PV_MOD
  101.     , PV_MP
  102.     , PV_MPS
  103.     , PV_NF
  104.     , PV_NU
  105.     , PV_OFT
  106.     , PV_PATH
  107.     , PV_PVW
  108.     , PV_RL
  109.     , PV_RO
  110.     , PV_SCBIND
  111.     , PV_SCROLL
  112.     , PV_SI
  113.     , PV_SN
  114.     , PV_STS
  115.     , PV_SUA
  116.     , PV_SW
  117.     , PV_SWF
  118.     , PV_SYN
  119.     , PV_TAGS
  120.     , PV_TS
  121.     , PV_TSR
  122.     , PV_TW
  123.     , PV_TX
  124.     , PV_WM
  125.     , PV_WRAP
  126. } idopt_T;
  127.  
  128. /*
  129.  * Options local to a window have a value local to a buffer and global to all
  130.  * buffers.  Indicate this by setting "var" to VAR_WIN.
  131.  */
  132. #define VAR_WIN ((char_u *)-1)
  133.  
  134. /*
  135.  * These the global values for options which are also local to a buffer.
  136.  * Only to be used in option.c!
  137.  */
  138. static int    p_ai;
  139. static int    p_bin;
  140. #ifdef FEAT_MBYTE
  141. static int    p_bomb;
  142. #endif
  143. #if defined(FEAT_QUICKFIX)
  144. static char_u    *p_bh;
  145. static char_u    *p_bt;
  146. #endif
  147. static int    p_bl;
  148. #ifdef FEAT_CINDENT
  149. static int    p_cin;
  150. static char_u    *p_cink;
  151. static char_u    *p_cino;
  152. #endif
  153. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  154. static char_u    *p_cinw;
  155. #endif
  156. #ifdef FEAT_COMMENTS
  157. static char_u    *p_com;
  158. #endif
  159. #ifdef FEAT_FOLDING
  160. static char_u    *p_cms;
  161. #endif
  162. #ifdef FEAT_INS_EXPAND
  163. static char_u    *p_cpt;
  164. #endif
  165. static int    p_eol;
  166. static int    p_et;
  167. #ifdef FEAT_MBYTE
  168. static char_u    *p_fenc;
  169. #endif
  170. static char_u    *p_ff;
  171. static char_u    *p_fo;
  172. #ifdef FEAT_AUTOCMD
  173. static char_u    *p_ft;
  174. #endif
  175. static long    p_iminsert;
  176. static long    p_imsearch;
  177. #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
  178. static char_u    *p_inex;
  179. #endif
  180. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  181. static char_u    *p_inde;
  182. static char_u    *p_indk;
  183. #endif
  184. static int    p_inf;
  185. static char_u    *p_isk;
  186. #ifdef FEAT_CRYPT
  187. static char_u    *p_key;
  188. #endif
  189. #ifdef FEAT_LISP
  190. static int    p_lisp;
  191. #endif
  192. static int    p_ml;
  193. static int    p_ma;
  194. static int    p_mod;
  195. static char_u    *p_mps;
  196. static char_u    *p_nf;
  197. #ifdef FEAT_OSFILETYPE
  198. static char_u    *p_oft;
  199. #endif
  200. static int    p_ro;
  201. #ifdef FEAT_SMARTINDENT
  202. static int    p_si;
  203. #endif
  204. #ifndef SHORT_FNAME
  205. static int    p_sn;
  206. #endif
  207. static long    p_sts;
  208. #if defined(FEAT_SEARCHPATH)
  209. static char_u    *p_sua;
  210. #endif
  211. static long    p_sw;
  212. static int    p_swf;
  213. #ifdef FEAT_SYN_HL
  214. static char_u    *p_syn;
  215. #endif
  216. static long    p_ts;
  217. static long    p_tw;
  218. static int    p_tx;
  219. static long    p_wm;
  220. #ifdef FEAT_KEYMAP
  221. static char_u    *p_keymap;
  222. #endif
  223.  
  224. /* Saved values for when 'bin' is set. */
  225. static int    p_et_nobin;
  226. static int    p_ml_nobin;
  227. static long    p_tw_nobin;
  228. static long    p_wm_nobin;
  229.  
  230. /* Saved values for when 'paste' is set */
  231. static long    p_tw_nopaste;
  232. static long    p_wm_nopaste;
  233. static long    p_sts_nopaste;
  234. static int    p_ai_nopaste;
  235.  
  236. struct vimoption
  237. {
  238.     char    *fullname;    /* full option name */
  239.     char    *shortname;    /* permissible abbreviation */
  240.     long_u    flags;        /* see below */
  241.     char_u    *var;        /* global option: pointer to variable;
  242.                  * window-local option: VAR_WIN;
  243.                  * buffer-local option: global value */
  244.     idopt_T    indir;        /* global option: PV_NONE;
  245.                  * local option: indirect option index */
  246.     char_u    *def_val[2];    /* default values for variable (vi and vim) */
  247. #ifdef FEAT_EVAL
  248.     scid_T    scriptID;    /* script in which the option was last set */
  249. #endif
  250. };
  251.  
  252. #define VI_DEFAULT  0        /* def_val[VI_DEFAULT] is Vi default value */
  253. #define VIM_DEFAULT 1        /* def_val[VIM_DEFAULT] is Vim default value */
  254.  
  255. /*
  256.  * Flags
  257.  */
  258. #define P_BOOL        0x01    /* the option is boolean */
  259. #define P_NUM        0x02    /* the option is numeric */
  260. #define P_STRING    0x04    /* the option is a string */
  261. #define P_ALLOCED    0x08    /* the string option is in allocated memory,
  262.                     must use vim_free() when assigning new
  263.                     value. Not set if default is the same. */
  264. #define P_EXPAND    0x10    /* environment expansion.  NOTE: P_EXPAND can
  265.                    never be used for local or hidden options! */
  266. #define P_NODEFAULT    0x40    /* don't set to default value */
  267. #define P_DEF_ALLOCED    0x80    /* default value is in allocated memory, must
  268.                     use vim_free() when assigning new value */
  269. #define P_WAS_SET    0x100    /* option has been set/reset */
  270. #define P_NO_MKRC    0x200    /* don't include in :mkvimrc output */
  271. #define P_VI_DEF    0x400    /* Use Vi default for Vim */
  272. #define P_VIM        0x800    /* Vim option, reset when 'cp' set */
  273.  
  274.                 /* when option changed, what to display: */
  275. #define P_RSTAT        0x1000    /* redraw status lines */
  276. #define P_RWIN        0x2000    /* redraw current window */
  277. #define P_RBUF        0x4000    /* redraw current buffer */
  278. #define P_RALL        0x6000    /* redraw all windows */
  279. #define P_RCLR        0x7000    /* clear and redraw all */
  280.  
  281. #define P_COMMA        0x8000    /* comma separated list */
  282. #define P_NODUP        0x10000L/* don't allow duplicate strings */
  283. #define P_FLAGLIST    0x20000L/* list of single-char flags */
  284.  
  285. #define P_SECURE    0x40000L/* cannot change in modeline or secure mode */
  286.  
  287. /*
  288.  * options[] is initialized here.
  289.  * The order of the options MUST be alphabetic for ":set all" and findoption().
  290.  * All option names MUST start with a lowercase letter (for findoption()).
  291.  * Exception: "t_" options are at the end.
  292.  * The options with a NULL variable are 'hidden': a set command for them is
  293.  * ignored and they are not printed.
  294.  */
  295. static struct vimoption
  296. #ifdef FEAT_GUI_W16
  297.     _far
  298. #endif
  299.     options[] =
  300. {
  301.     {"aleph",        "al",   P_NUM|P_VI_DEF,
  302. #ifdef FEAT_RIGHTLEFT
  303.                 (char_u *)&p_aleph, PV_NONE,
  304. #else
  305.                 (char_u *)NULL, PV_NONE,
  306. #endif
  307.                 {
  308. #if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
  309.                 (char_u *)128L,
  310. #else
  311.                 (char_u *)224L,
  312. #endif
  313.                         (char_u *)0L}},
  314.     {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
  315. #ifdef FEAT_RIGHTLEFT
  316.                 (char_u *)&p_ari, PV_NONE,
  317. #else
  318.                 (char_u *)NULL, PV_NONE,
  319. #endif
  320.                 {(char_u *)FALSE, (char_u *)0L}},
  321.     {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
  322. #ifdef FEAT_FKMAP
  323.                 (char_u *)&p_altkeymap, PV_NONE,
  324. #else
  325.                 (char_u *)NULL, PV_NONE,
  326. #endif
  327.                 {(char_u *)FALSE, (char_u *)0L}},
  328.     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
  329.                 (char_u *)&p_ai, PV_AI,
  330.                 {(char_u *)FALSE, (char_u *)0L}},
  331.     {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
  332.                 (char_u *)NULL, PV_NONE,
  333.                 {(char_u *)FALSE, (char_u *)0L}},
  334.     {"autoread",    "ar",   P_BOOL|P_VI_DEF,
  335.                 (char_u *)&p_ar, OPT_BOTH(PV_AR),
  336.                 {(char_u *)FALSE, (char_u *)0L}},
  337.     {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
  338.                 (char_u *)&p_aw, PV_NONE,
  339.                 {(char_u *)FALSE, (char_u *)0L}},
  340.     {"autowriteall","awa",  P_BOOL|P_VI_DEF,
  341.                 (char_u *)&p_awa, PV_NONE,
  342.                 {(char_u *)FALSE, (char_u *)0L}},
  343.     {"background",  "bg",   P_STRING|P_VI_DEF|P_RCLR,
  344.                 (char_u *)&p_bg, PV_NONE,
  345.                 {
  346. #if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
  347.                 (char_u *)"dark",
  348. #else
  349.                 (char_u *)"light",
  350. #endif
  351.                         (char_u *)0L}},
  352.     {"backspace",   "bs",   P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
  353.                 (char_u *)&p_bs, PV_NONE,
  354.                 {(char_u *)"", (char_u *)0L}},
  355.     {"backup",        "bk",   P_BOOL|P_VI_DEF|P_VIM,
  356.                 (char_u *)&p_bk, PV_NONE,
  357.                 {(char_u *)FALSE, (char_u *)0L}},
  358.     {"backupcopy",  "bkc",  P_STRING|P_VIM,
  359.                 (char_u *)&p_bkc, PV_NONE,
  360. #ifdef UNIX
  361.                 {(char_u *)"yes", (char_u *)"auto"}
  362. #else
  363.                 {(char_u *)"auto", (char_u *)"auto"}
  364. #endif
  365.                 },
  366.     {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
  367.                 (char_u *)&p_bdir, PV_NONE,
  368.                 {(char_u *)DFLT_BDIR, (char_u *)0L}},
  369.     {"backupext",   "bex",  P_STRING|P_VI_DEF,
  370.                 (char_u *)&p_bex, PV_NONE,
  371.                 {
  372. #ifdef VMS
  373.                 (char_u *)"_",
  374. #else
  375.                 (char_u *)"~",
  376. #endif
  377.                         (char_u *)0L}},
  378.     {"backupskip",  "bsk",  P_STRING|P_VI_DEF|P_COMMA,
  379. #ifdef FEAT_WILDIGN
  380.                 (char_u *)&p_bsk, PV_NONE,
  381.                 {(char_u *)"", (char_u *)0L}
  382. #else
  383.                 (char_u *)NULL, PV_NONE,
  384.                 {(char_u *)0L, (char_u *)0L}
  385. #endif
  386.                 },
  387. #ifdef FEAT_BEVAL
  388.     {"balloondelay","bdlay",P_NUM|P_VI_DEF,
  389.                 (char_u *)&p_bdlay, PV_NONE,
  390.                 {(char_u *)600L, (char_u *)0L}},
  391. #endif
  392. #ifdef FEAT_SUN_WORKSHOP
  393.     {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
  394.                 (char_u *)&p_beval, PV_NONE,
  395.                 {(char_u*)FALSE, (char_u *)0L}},
  396. #endif
  397.     {"beautify",    "bf",   P_BOOL|P_VI_DEF,
  398.                 (char_u *)NULL, PV_NONE,
  399.                 {(char_u *)FALSE, (char_u *)0L}},
  400.     {"binary",        "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
  401.                 (char_u *)&p_bin, PV_BIN,
  402.                 {(char_u *)FALSE, (char_u *)0L}},
  403.     {"bioskey",        "biosk",P_BOOL|P_VI_DEF,
  404. #ifdef MSDOS
  405.                 (char_u *)&p_biosk, PV_NONE,
  406. #else
  407.                 (char_u *)NULL, PV_NONE,
  408. #endif
  409.                 {(char_u *)TRUE, (char_u *)0L}},
  410.     {"bomb",        NULL,   P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
  411. #ifdef FEAT_MBYTE
  412.                 (char_u *)&p_bomb, PV_BOMB,
  413. #else
  414.                 (char_u *)NULL, PV_NONE,
  415. #endif
  416.                 {(char_u *)FALSE, (char_u *)0L}},
  417.     {"breakat",        "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
  418. #ifdef FEAT_LINEBREAK
  419.                 (char_u *)&p_breakat, PV_NONE,
  420.                 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
  421. #else
  422.                 (char_u *)NULL, PV_NONE,
  423.                 {(char_u *)0L, (char_u *)0L}
  424. #endif
  425.                 },
  426.     {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
  427. #ifdef FEAT_BROWSE
  428.                 (char_u *)&p_bsdir, PV_NONE,
  429.                 {(char_u *)"last", (char_u *)0L}
  430. #else
  431.                 (char_u *)NULL, PV_NONE,
  432.                 {(char_u *)0L, (char_u *)0L}
  433. #endif
  434.                 },
  435.     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF,
  436. #if defined(FEAT_QUICKFIX)
  437.                 (char_u *)&p_bh, PV_BH,
  438.                 {(char_u *)"", (char_u *)0L}
  439. #else
  440.                 (char_u *)NULL, PV_NONE,
  441.                 {(char_u *)0L, (char_u *)0L}
  442. #endif
  443.                 },
  444.     {"buflisted",   "bl",   P_BOOL|P_VI_DEF,
  445.                 (char_u *)&p_bl, PV_BL,
  446.                 {(char_u *)1L, (char_u *)0L}
  447.                 },
  448.     {"buftype",        "bt",   P_STRING|P_ALLOCED|P_VI_DEF,
  449. #if defined(FEAT_QUICKFIX)
  450.                 (char_u *)&p_bt, PV_BT,
  451.                 {(char_u *)"", (char_u *)0L}
  452. #else
  453.                 (char_u *)NULL, PV_NONE,
  454.                 {(char_u *)0L, (char_u *)0L}
  455. #endif
  456.                 },
  457.     {"cdpath",        "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  458. #ifdef FEAT_SEARCHPATH
  459.                 (char_u *)&p_cdpath, PV_NONE,
  460.                 {(char_u *)",,", (char_u *)0L}
  461. #else
  462.                 (char_u *)NULL, PV_NONE,
  463.                 {(char_u *)0L, (char_u *)0L}
  464. #endif
  465.                 },
  466.     {"cedit",        NULL,   P_STRING,
  467. #ifdef FEAT_CMDWIN
  468.                 (char_u *)&p_cedit, PV_NONE,
  469.                 {(char_u *)"", (char_u *)CTRL_F_STR}
  470. #else
  471.                 (char_u *)NULL, PV_NONE,
  472.                 {(char_u *)0L, (char_u *)0L}
  473. #endif
  474.                 },
  475.     {"charconvert",  "ccv", P_STRING|P_VI_DEF|P_SECURE,
  476. #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
  477.                 (char_u *)&p_ccv, PV_NONE,
  478.                 {(char_u *)"", (char_u *)0L}
  479. #else
  480.                 (char_u *)NULL, PV_NONE,
  481.                 {(char_u *)0L, (char_u *)0L}
  482. #endif
  483.                 },
  484.     {"cindent",        "cin",  P_BOOL|P_VI_DEF|P_VIM,
  485. #ifdef FEAT_CINDENT
  486.                 (char_u *)&p_cin, PV_CIN,
  487. #else
  488.                 (char_u *)NULL, PV_NONE,
  489. #endif
  490.                 {(char_u *)FALSE, (char_u *)0L}},
  491.     {"cinkeys",        "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  492. #ifdef FEAT_CINDENT
  493.                 (char_u *)&p_cink, PV_CINK,
  494.                 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
  495. #else
  496.                 (char_u *)NULL, PV_NONE,
  497.                 {(char_u *)0L, (char_u *)0L}
  498. #endif
  499.                 },
  500.     {"cinoptions",  "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  501. #ifdef FEAT_CINDENT
  502.                 (char_u *)&p_cino, PV_CINO,
  503. #else
  504.                 (char_u *)NULL, PV_NONE,
  505. #endif
  506.                 {(char_u *)"", (char_u *)0L}},
  507.     {"cinwords",    "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  508. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  509.                 (char_u *)&p_cinw, PV_CINW,
  510.                 {(char_u *)"if,else,while,do,for,switch",
  511.                 (char_u *)0L}
  512. #else
  513.                 (char_u *)NULL, PV_NONE,
  514.                 {(char_u *)0L, (char_u *)0L}
  515. #endif
  516.                 },
  517.     {"clipboard",   "cb",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  518. #ifdef FEAT_CLIPBOARD
  519.                 (char_u *)&p_cb, PV_NONE,
  520. # ifdef FEAT_XCLIPBOARD
  521.                 {(char_u *)"autoselect,exclude:cons\\|linux",
  522.                                    (char_u *)0L}},
  523. # else
  524.                 {(char_u *)"", (char_u *)0L}},
  525. # endif
  526. #else
  527.                 (char_u *)NULL, PV_NONE,
  528.                 {(char_u *)"", (char_u *)0L}},
  529. #endif
  530.     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
  531.                 (char_u *)&p_ch, PV_NONE,
  532.                 {(char_u *)1L, (char_u *)0L}},
  533.     {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
  534. #ifdef FEAT_CMDWIN
  535.                 (char_u *)&p_cwh, PV_NONE,
  536. #else
  537.                 (char_u *)NULL, PV_NONE,
  538. #endif
  539.                 {(char_u *)7L, (char_u *)0L}},
  540.     {"columns",        "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
  541.                 (char_u *)&Columns, PV_NONE,
  542.                 {(char_u *)80L, (char_u *)0L}},
  543.     {"comments",    "com",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  544. #ifdef FEAT_COMMENTS
  545.                 (char_u *)&p_com, PV_COM,
  546.                 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
  547.                 (char_u *)0L}
  548. #else
  549.                 (char_u *)NULL, PV_NONE,
  550.                 {(char_u *)0L, (char_u *)0L}
  551. #endif
  552.                 },
  553.     {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
  554. #ifdef FEAT_FOLDING
  555.                 (char_u *)&p_cms, PV_CMS,
  556.                 {(char_u *)"/*%s*/", (char_u *)0L}
  557. #else
  558.                 (char_u *)NULL, PV_NONE,
  559.                 {(char_u *)0L, (char_u *)0L}
  560. #endif
  561.                 },
  562.     {"compatible",  "cp",   P_BOOL|P_RALL,
  563.                 (char_u *)&p_cp, PV_NONE,
  564.                 {(char_u *)TRUE, (char_u *)FALSE}},
  565.     {"complete",    "cpt",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  566. #ifdef FEAT_INS_EXPAND
  567.                 (char_u *)&p_cpt, PV_CPT,
  568.                 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
  569. #else
  570.                 (char_u *)NULL, PV_NONE,
  571.                 {(char_u *)0L, (char_u *)0L}
  572. #endif
  573.                 },
  574.     {"confirm",     "cf",   P_BOOL|P_VI_DEF,
  575. #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
  576.                 (char_u *)&p_confirm, PV_NONE,
  577. #else
  578.                 (char_u *)NULL, PV_NONE,
  579. #endif
  580.                 {(char_u *)FALSE, (char_u *)0L}},
  581.     {"conskey",        "consk",P_BOOL|P_VI_DEF,
  582. #ifdef MSDOS
  583.                 (char_u *)&p_consk, PV_NONE,
  584. #else
  585.                 (char_u *)NULL, PV_NONE,
  586. #endif
  587.                 {(char_u *)FALSE, (char_u *)0L}},
  588.     {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL|P_FLAGLIST,
  589.                 (char_u *)&p_cpo, PV_NONE,
  590.                 {(char_u *)CPO_ALL, (char_u *)CPO_DEFAULT}},
  591.     {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
  592. #ifdef USE_CSCOPE
  593.                 (char_u *)&p_cspc, PV_NONE,
  594. #else
  595.                 (char_u *)NULL, PV_NONE,
  596. #endif
  597.                 {(char_u *)0L, (char_u *)0L}},
  598.     {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  599. #ifdef FEAT_CSCOPE
  600.                 (char_u *)&p_csprg, PV_NONE,
  601.                 {(char_u *)"cscope", (char_u *)0L}
  602. #else
  603.                 (char_u *)NULL, PV_NONE,
  604.                 {(char_u *)0L, (char_u *)0L}
  605. #endif
  606.                 },
  607.     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
  608. #ifdef FEAT_CSCOPE
  609.                 (char_u *)&p_cst, PV_NONE,
  610. #else
  611.                 (char_u *)NULL, PV_NONE,
  612. #endif
  613.                 {(char_u *)0L, (char_u *)0L}},
  614.     {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
  615. #ifdef FEAT_CSCOPE
  616.                 (char_u *)&p_csto, PV_NONE,
  617. #else
  618.                 (char_u *)NULL, PV_NONE,
  619. #endif
  620.                 {(char_u *)0L, (char_u *)0L}},
  621.     {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
  622. #ifdef FEAT_CSCOPE
  623.                 (char_u *)&p_csverbose, PV_NONE,
  624. #else
  625.                 (char_u *)NULL, PV_NONE,
  626. #endif
  627.                 {(char_u *)0L, (char_u *)0L}},
  628.     {"debug",        NULL,   P_STRING|P_VI_DEF,
  629.                 (char_u *)&p_debug, PV_NONE,
  630.                 {(char_u *)"", (char_u *)0L}},
  631.     {"define",        "def",  P_STRING|P_ALLOCED|P_VI_DEF,
  632. #ifdef FEAT_FIND_ID
  633.                 (char_u *)&p_def, OPT_BOTH(PV_DEF),
  634.                 {(char_u *)"^#\\s*define", (char_u *)0L}
  635. #else
  636.                 (char_u *)NULL, PV_NONE,
  637.                 {(char_u *)NULL, (char_u *)0L}
  638. #endif
  639.                 },
  640.     {"delcombine", "deco",  P_BOOL|P_VI_DEF|P_VIM,
  641. #ifdef FEAT_MBYTE
  642.                 (char_u *)&p_deco, PV_NONE,
  643. #else
  644.                 (char_u *)NULL, PV_NONE,
  645. #endif
  646.                 {(char_u *)FALSE, (char_u *)0L}
  647.                 },
  648.     {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  649. #ifdef FEAT_INS_EXPAND
  650.                 (char_u *)&p_dict, OPT_BOTH(PV_DICT),
  651. #else
  652.                 (char_u *)NULL, PV_NONE,
  653. #endif
  654.                 {(char_u *)"", (char_u *)0L}},
  655.     {"diff",        NULL,   P_BOOL|P_VI_DEF|P_RWIN,
  656. #ifdef FEAT_DIFF
  657.                 (char_u *)VAR_WIN, PV_DIFF,
  658. #else
  659.                 (char_u *)NULL, PV_NONE,
  660. #endif
  661.                 {(char_u *)FALSE, (char_u *)0L}},
  662.     {"diffexpr",    "dex",  P_STRING|P_VI_DEF|P_SECURE,
  663. #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
  664.                 (char_u *)&p_dex, PV_NONE,
  665.                 {(char_u *)"", (char_u *)0L}
  666. #else
  667.                 (char_u *)NULL, PV_NONE,
  668.                 {(char_u *)0L, (char_u *)0L}
  669. #endif
  670.                 },
  671.     {"diffopt",        "dip",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
  672. #ifdef FEAT_DIFF
  673.                 (char_u *)&p_dip, PV_NONE,
  674.                 {(char_u *)"filler", (char_u *)NULL}
  675. #else
  676.                 (char_u *)NULL, PV_NONE,
  677.                 {(char_u *)"", (char_u *)NULL}
  678. #endif
  679.                 },
  680.     {"digraph",        "dg",   P_BOOL|P_VI_DEF|P_VIM,
  681. #ifdef FEAT_DIGRAPHS
  682.                 (char_u *)&p_dg, PV_NONE,
  683. #else
  684.                 (char_u *)NULL, PV_NONE,
  685. #endif
  686.                 {(char_u *)FALSE, (char_u *)0L}},
  687.     {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
  688.                 (char_u *)&p_dir, PV_NONE,
  689.                 {(char_u *)DFLT_DIR, (char_u *)0L}},
  690.     {"display",        "dy",   P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
  691.                 (char_u *)&p_dy, PV_NONE,
  692.                 {(char_u *)"", (char_u *)0L}},
  693.     {"eadirection", "ead",  P_STRING|P_VI_DEF,
  694. #ifdef FEAT_VERTSPLIT
  695.                 (char_u *)&p_ead, PV_NONE,
  696.                 {(char_u *)"both", (char_u *)0L}
  697. #else
  698.                 (char_u *)NULL, PV_NONE,
  699.                 {(char_u *)NULL, (char_u *)0L}
  700. #endif
  701.                 },
  702.     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
  703.                 (char_u *)&p_ed, PV_NONE,
  704.                 {(char_u *)FALSE, (char_u *)0L}},
  705.     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR,
  706. #ifdef FEAT_MBYTE
  707.                 (char_u *)&p_enc, PV_NONE,
  708.                 {(char_u *)ENC_DFLT, (char_u *)0L}
  709. #else
  710.                 (char_u *)NULL, PV_NONE,
  711.                 {(char_u *)0L, (char_u *)0L}
  712. #endif
  713.                 },
  714.     {"endofline",   "eol",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
  715.                 (char_u *)&p_eol, PV_EOL,
  716.                 {(char_u *)TRUE, (char_u *)0L}},
  717.     {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
  718.                 (char_u *)&p_ea, PV_NONE,
  719.                 {(char_u *)TRUE, (char_u *)0L}},
  720.     {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  721.                 (char_u *)&p_ep, OPT_BOTH(PV_EP),
  722.                 {(char_u *)"", (char_u *)0L}},
  723.     {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
  724.                 (char_u *)&p_eb, PV_NONE,
  725.                 {(char_u *)FALSE, (char_u *)0L}},
  726.     {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  727. #ifdef FEAT_QUICKFIX
  728.                 (char_u *)&p_ef, PV_NONE,
  729.                 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
  730. #else
  731.                 (char_u *)NULL, PV_NONE,
  732.                 {(char_u *)NULL, (char_u *)0L}
  733. #endif
  734.                 },
  735.     {"errorformat", "efm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  736. #ifdef FEAT_QUICKFIX
  737.                 (char_u *)&p_efm, OPT_BOTH(PV_EFM),
  738.                 {(char_u *)DFLT_EFM, (char_u *)0L},
  739. #else
  740.                 (char_u *)NULL, PV_NONE,
  741.                 {(char_u *)NULL, (char_u *)0L}
  742. #endif
  743.                 },
  744.     {"esckeys",        "ek",   P_BOOL|P_VIM,
  745.                 (char_u *)&p_ek, PV_NONE,
  746.                 {(char_u *)FALSE, (char_u *)TRUE}},
  747.     {"eventignore", "ei",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  748. #ifdef FEAT_AUTOCMD
  749.                 (char_u *)&p_ei, PV_NONE,
  750. #else
  751.                 (char_u *)NULL, PV_NONE,
  752. #endif
  753.                 {(char_u *)"", (char_u *)0L}},
  754.     {"expandtab",   "et",   P_BOOL|P_VI_DEF|P_VIM,
  755.                 (char_u *)&p_et, PV_ET,
  756.                 {(char_u *)FALSE, (char_u *)0L}},
  757.     {"exrc",        "ex",   P_BOOL|P_VI_DEF|P_SECURE,
  758.                 (char_u *)&p_exrc, PV_NONE,
  759.                 {(char_u *)FALSE, (char_u *)0L}},
  760.     {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
  761. #ifdef FEAT_MBYTE
  762.                 (char_u *)&p_fenc, PV_FENC,
  763.                 {(char_u *)"", (char_u *)0L}
  764. #else
  765.                 (char_u *)NULL, PV_NONE,
  766.                 {(char_u *)0L, (char_u *)0L}
  767. #endif
  768.                 },
  769.     {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
  770. #ifdef FEAT_MBYTE
  771.                 (char_u *)&p_fencs, PV_NONE,
  772.                 {(char_u *)"ucs-bom", (char_u *)0L}
  773. #else
  774.                 (char_u *)NULL, PV_NONE,
  775.                 {(char_u *)0L, (char_u *)0L}
  776. #endif
  777.                 },
  778.     {"fileformat",  "ff",   P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
  779.                 (char_u *)&p_ff, PV_FF,
  780.                 {(char_u *)DFLT_FF, (char_u *)0L}},
  781.     {"fileformats", "ffs",  P_STRING|P_VIM|P_COMMA|P_NODUP,
  782.                 (char_u *)&p_ffs, PV_NONE,
  783.                 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
  784.     {"filetype",    "ft",   P_STRING|P_ALLOCED|P_VI_DEF,
  785. #ifdef FEAT_AUTOCMD
  786.                 (char_u *)&p_ft, PV_FT,
  787.                 {(char_u *)"", (char_u *)0L}
  788. #else
  789.                 (char_u *)NULL, PV_NONE,
  790.                 {(char_u *)0L, (char_u *)0L}
  791. #endif
  792.                 },
  793.     {"fillchars",   "fcs",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
  794. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  795.                 (char_u *)&p_fcs, PV_NONE,
  796.                 {(char_u *)"vert:|,fold:-", (char_u *)0L}
  797. #else
  798.                 (char_u *)NULL, PV_NONE,
  799.                 {(char_u *)"", (char_u *)0L}
  800. #endif
  801.                 },
  802.     {"fkmap",        "fk",   P_BOOL|P_VI_DEF,
  803. #ifdef FEAT_FKMAP
  804.                 (char_u *)&p_fkmap, PV_NONE,
  805. #else
  806.                 (char_u *)NULL, PV_NONE,
  807. #endif
  808.                 {(char_u *)FALSE, (char_u *)0L}},
  809.     {"flash",        "fl",   P_BOOL|P_VI_DEF,
  810.                 (char_u *)NULL, PV_NONE,
  811.                 {(char_u *)FALSE, (char_u *)0L}},
  812. #ifdef FEAT_FOLDING
  813.     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
  814.                 (char_u *)&p_fcl, PV_NONE,
  815.                 {(char_u *)"", (char_u *)0L}},
  816.     {"foldcolumn",  "fdc",  P_NUM|P_VI_DEF|P_RWIN,
  817.                 (char_u *)VAR_WIN, PV_FDC,
  818.                 {(char_u *)FALSE, (char_u *)0L}},
  819.     {"foldenable",  "fen",  P_BOOL|P_VI_DEF|P_RWIN,
  820.                 (char_u *)VAR_WIN, PV_FEN,
  821.                 {(char_u *)TRUE, (char_u *)0L}},
  822.     {"foldexpr",    "fde",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  823. # ifdef FEAT_EVAL
  824.                 (char_u *)VAR_WIN, PV_FDE,
  825.                 {(char_u *)"0", (char_u *)NULL}
  826. # else
  827.                 (char_u *)NULL, PV_NONE,
  828.                 {(char_u *)NULL, (char_u *)0L}
  829. # endif
  830.                 },
  831.     {"foldignore",  "fdi",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  832.                 (char_u *)VAR_WIN, PV_FDI,
  833.                 {(char_u *)"#", (char_u *)NULL}},
  834.     {"foldlevel",   "fdl",  P_NUM|P_VI_DEF|P_RWIN,
  835.                 (char_u *)VAR_WIN, PV_FDL,
  836.                 {(char_u *)0L, (char_u *)0L}},
  837.     {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
  838.                 (char_u *)&p_fdls, PV_NONE,
  839.                 {(char_u *)-1L, (char_u *)0L}},
  840.     {"foldmarker",  "fmr",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
  841.                                P_RWIN|P_COMMA|P_NODUP,
  842.                 (char_u *)VAR_WIN, PV_FMR,
  843.                 {(char_u *)"{{{,}}}", (char_u *)NULL}},
  844.     {"foldmethod",  "fdm",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  845.                 (char_u *)VAR_WIN, PV_FDM,
  846.                 {(char_u *)"manual", (char_u *)NULL}},
  847.     {"foldminlines","fml",  P_NUM|P_VI_DEF|P_RWIN,
  848.                 (char_u *)VAR_WIN, PV_FML,
  849.                 {(char_u *)1L, (char_u *)0L}},
  850.     {"foldnestmax", "fdn",  P_NUM|P_VI_DEF|P_RWIN,
  851.                 (char_u *)VAR_WIN, PV_FDN,
  852.                 {(char_u *)20L, (char_u *)0L}},
  853.     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  854.                 (char_u *)&p_fdo, PV_NONE,
  855.          {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
  856.                                    (char_u *)0L}},
  857.     {"foldtext",    "fdt",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
  858. # ifdef FEAT_EVAL
  859.                 (char_u *)VAR_WIN, PV_FDT,
  860.                 {(char_u *)"foldtext()", (char_u *)NULL}
  861. #else
  862.                 (char_u *)NULL, PV_NONE,
  863.                 {(char_u *)NULL, (char_u *)0L}
  864. #endif
  865.                 },
  866. #endif
  867.     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
  868.                 (char_u *)&p_fo, PV_FO,
  869.                 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
  870.     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  871.                 (char_u *)&p_fp, PV_NONE,
  872.                 {(char_u *)"", (char_u *)0L}},
  873.     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
  874.                 (char_u *)&p_gd, PV_NONE,
  875.                 {(char_u *)FALSE, (char_u *)0L}},
  876.     {"graphic",        "gr",   P_BOOL|P_VI_DEF,
  877.                 (char_u *)NULL, PV_NONE,
  878.                 {(char_u *)FALSE, (char_u *)0L}},
  879.     {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  880. #ifdef FEAT_QUICKFIX
  881.                 (char_u *)&p_gefm, PV_NONE,
  882.                 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
  883. #else
  884.                 (char_u *)NULL, PV_NONE,
  885.                 {(char_u *)NULL, (char_u *)0L}
  886. #endif
  887.                 },
  888.     {"grepprg",        "gp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  889. #ifdef FEAT_QUICKFIX
  890.                 (char_u *)&p_gp, OPT_BOTH(PV_GP),
  891.                 {
  892. # ifdef WIN3264
  893.                 /* may be changed to "grep -n" in os_win32.c */
  894.                 (char_u *)"findstr /n",
  895. # else
  896. #  ifdef UNIX
  897.                 /* Add an extra file name so that grep will always
  898.                  * insert a file name in the match line. */
  899.                 (char_u *)"grep -n $* /dev/null",
  900. #  else
  901. #   ifdef VMS
  902.                 (char_u *)"SEARCH/NUMBERS ",
  903. #   else
  904.                 (char_u *)"grep -n ",
  905. #endif
  906. #endif
  907. # endif
  908.                 (char_u *)0L},
  909. #else
  910.                 (char_u *)NULL, PV_NONE,
  911.                 {(char_u *)NULL, (char_u *)0L}
  912. #endif
  913.                 },
  914.     {"guicursor",    "gcr",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  915. #ifdef CURSOR_SHAPE
  916.                 (char_u *)&p_guicursor, PV_NONE,
  917.                 {
  918. # ifdef FEAT_GUI
  919.                 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
  920. # else    /* MSDOS or Win32 console */
  921.                 (char_u *)"n-v-c:block,o:hor50,i-ci:hor10,r-cr:hor30,sm:block",
  922. # endif
  923.                     (char_u *)0L}
  924. #else
  925.                 (char_u *)NULL, PV_NONE,
  926.                 {(char_u *)NULL, (char_u *)0L}
  927. #endif
  928.                     },
  929.     {"guifont",        "gfn",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
  930. #ifdef FEAT_GUI
  931.                 (char_u *)&p_guifont, PV_NONE,
  932.                 {(char_u *)"", (char_u *)0L}
  933. #else
  934.                 (char_u *)NULL, PV_NONE,
  935.                 {(char_u *)NULL, (char_u *)0L}
  936. #endif
  937.                     },
  938.     {"guifontset",  "gfs",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
  939. #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
  940.                 (char_u *)&p_guifontset, PV_NONE,
  941.                 {(char_u *)"", (char_u *)0L}
  942. #else
  943.                 (char_u *)NULL, PV_NONE,
  944.                 {(char_u *)NULL, (char_u *)0L}
  945. #endif
  946.                     },
  947.     {"guifontwide", "gfw",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
  948. #if defined(FEAT_GUI) && defined(FEAT_MBYTE)
  949.                 (char_u *)&p_guifontwide, PV_NONE,
  950.                 {(char_u *)"", (char_u *)0L}
  951. #else
  952.                 (char_u *)NULL, PV_NONE,
  953.                 {(char_u *)NULL, (char_u *)0L}
  954. #endif
  955.                     },
  956.     {"guiheadroom", "ghr",  P_NUM|P_VI_DEF,
  957. #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
  958.                 (char_u *)&p_ghr, PV_NONE,
  959. #else
  960.                 (char_u *)NULL, PV_NONE,
  961. #endif
  962.                 {(char_u *)50L, (char_u *)0L}},
  963.     {"guioptions",  "go",   P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
  964. #if defined(FEAT_GUI)
  965.                 (char_u *)&p_go, PV_NONE,
  966. # ifdef UNIX
  967.                 {(char_u *)"agimrLtT", (char_u *)0L}
  968. # else
  969.                 {(char_u *)"gmrLtT", (char_u *)0L}
  970. # endif
  971. #else
  972.                 (char_u *)NULL, PV_NONE,
  973.                 {(char_u *)NULL, (char_u *)0L}
  974. #endif
  975.                     },
  976.     {"guipty",        NULL,   P_BOOL|P_VI_DEF,
  977. #if defined(FEAT_GUI)
  978.                 (char_u *)&p_guipty, PV_NONE,
  979. #else
  980.                 (char_u *)NULL, PV_NONE,
  981. #endif
  982.                 {(char_u *)TRUE, (char_u *)0L}},
  983.     {"hardtabs",    "ht",   P_NUM|P_VI_DEF,
  984.                 (char_u *)NULL, PV_NONE,
  985.                 {(char_u *)0L, (char_u *)0L}},
  986.     {"helpfile",    "hf",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  987.                 (char_u *)&p_hf, PV_NONE,
  988.                 {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
  989.     {"helpheight",  "hh",   P_NUM|P_VI_DEF,
  990. #ifdef FEAT_WINDOWS
  991.                 (char_u *)&p_hh, PV_NONE,
  992. #else
  993.                 (char_u *)NULL, PV_NONE,
  994. #endif
  995.                 {(char_u *)20L, (char_u *)0L}},
  996.     {"hidden",        "hid",  P_BOOL|P_VI_DEF,
  997.                 (char_u *)&p_hid, PV_NONE,
  998.                 {(char_u *)FALSE, (char_u *)0L}},
  999.     {"highlight",   "hl",   P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
  1000.                 (char_u *)&p_hl, PV_NONE,
  1001.                 {(char_u *)"8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText",
  1002.                 (char_u *)0L}},
  1003.     {"history",        "hi",   P_NUM|P_VIM,
  1004.                 (char_u *)&p_hi, PV_NONE,
  1005.                 {(char_u *)0L, (char_u *)20L}},
  1006.     {"hkmap",        "hk",   P_BOOL|P_VI_DEF|P_VIM,
  1007. #ifdef FEAT_RIGHTLEFT
  1008.                 (char_u *)&p_hkmap, PV_NONE,
  1009. #else
  1010.                 (char_u *)NULL, PV_NONE,
  1011. #endif
  1012.                 {(char_u *)FALSE, (char_u *)0L}},
  1013.     {"hkmapp",        "hkp",  P_BOOL|P_VI_DEF|P_VIM,
  1014. #ifdef FEAT_RIGHTLEFT
  1015.                 (char_u *)&p_hkmapp, PV_NONE,
  1016. #else
  1017.                 (char_u *)NULL, PV_NONE,
  1018. #endif
  1019.                 {(char_u *)FALSE, (char_u *)0L}},
  1020.     {"hlsearch",    "hls",  P_BOOL|P_VI_DEF|P_VIM|P_RALL,
  1021.                 (char_u *)&p_hls, PV_NONE,
  1022.                 {(char_u *)FALSE, (char_u *)0L}},
  1023.     {"icon",        NULL,   P_BOOL|P_VI_DEF,
  1024. #ifdef FEAT_TITLE
  1025.                 (char_u *)&p_icon, PV_NONE,
  1026. #else
  1027.                 (char_u *)NULL, PV_NONE,
  1028. #endif
  1029.                 {(char_u *)FALSE, (char_u *)0L}},
  1030.     {"iconstring",  NULL,   P_STRING|P_VI_DEF,
  1031. #ifdef FEAT_TITLE
  1032.                 (char_u *)&p_iconstring, PV_NONE,
  1033. #else
  1034.                 (char_u *)NULL, PV_NONE,
  1035. #endif
  1036.                 {(char_u *)"", (char_u *)0L}},
  1037.     {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
  1038.                 (char_u *)&p_ic, PV_NONE,
  1039.                 {(char_u *)FALSE, (char_u *)0L}},
  1040.     {"imactivatekey","imak",P_STRING|P_VI_DEF,
  1041. #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
  1042.                 (char_u *)&p_imak, PV_NONE,
  1043. #else
  1044.                 (char_u *)NULL, PV_NONE,
  1045. #endif
  1046.                 {(char_u *)"", (char_u *)0L}},
  1047.     {"imcmdline",   "imc",  P_BOOL|P_VI_DEF,
  1048. #ifdef USE_IM_CONTROL
  1049.                 (char_u *)&p_imcmdline, PV_NONE,
  1050. #else
  1051.                 (char_u *)NULL, PV_NONE,
  1052. #endif
  1053.                 {(char_u *)FALSE, (char_u *)0L}},
  1054.     {"imdisable",   "imd",  P_BOOL|P_VI_DEF,
  1055. #ifdef USE_IM_CONTROL
  1056.                 (char_u *)&p_imdisable, PV_NONE,
  1057. #else
  1058.                 (char_u *)NULL, PV_NONE,
  1059. #endif
  1060. #ifdef __sgi
  1061.                 {(char_u *)TRUE, (char_u *)0L}},
  1062. #else
  1063.                 {(char_u *)FALSE, (char_u *)0L}},
  1064. #endif
  1065.     {"iminsert",    "imi",  P_NUM|P_VI_DEF,
  1066.                 (char_u *)&p_iminsert, PV_IMI,
  1067. #ifdef B_IMODE_IM
  1068.                 {(char_u *)B_IMODE_IM, (char_u *)0L}
  1069. #else
  1070.                 {(char_u *)B_IMODE_NONE, (char_u *)0L}
  1071. #endif
  1072.                 },
  1073.     {"imsearch",    "ims",  P_NUM|P_VI_DEF,
  1074.                 (char_u *)&p_imsearch, PV_IMS,
  1075. #ifdef B_IMODE_IM
  1076.                 {(char_u *)B_IMODE_IM, (char_u *)0L}
  1077. #else
  1078.                 {(char_u *)B_IMODE_NONE, (char_u *)0L}
  1079. #endif
  1080.                 },
  1081.     {"include",        "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
  1082. #ifdef FEAT_FIND_ID
  1083.                 (char_u *)&p_inc, OPT_BOTH(PV_INC),
  1084.                 {(char_u *)"^#\\s*include", (char_u *)0L}
  1085. #else
  1086.                 (char_u *)NULL, PV_NONE,
  1087.                 {(char_u *)0L, (char_u *)0L}
  1088. #endif
  1089.                 },
  1090.     {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
  1091. #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
  1092.                 (char_u *)&p_inex, PV_INEX,
  1093.                 {(char_u *)"", (char_u *)0L}
  1094. #else
  1095.                 (char_u *)NULL, PV_NONE,
  1096.                 {(char_u *)0L, (char_u *)0L}
  1097. #endif
  1098.                 },
  1099.     {"incsearch",   "is",   P_BOOL|P_VI_DEF|P_VIM,
  1100.                 (char_u *)&p_is, PV_NONE,
  1101.                 {(char_u *)FALSE, (char_u *)0L}},
  1102.     {"indentexpr", "inde",  P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
  1103. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  1104.                 (char_u *)&p_inde, PV_INDE,
  1105.                 {(char_u *)"", (char_u *)0L}
  1106. #else
  1107.                 (char_u *)NULL, PV_NONE,
  1108.                 {(char_u *)0L, (char_u *)0L}
  1109. #endif
  1110.                 },
  1111.     {"indentkeys", "indk",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  1112. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  1113.                 (char_u *)&p_indk, PV_INDK,
  1114.                 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
  1115. #else
  1116.                 (char_u *)NULL, PV_NONE,
  1117.                 {(char_u *)0L, (char_u *)0L}
  1118. #endif
  1119.                 },
  1120.     {"infercase",   "inf",  P_BOOL|P_VI_DEF,
  1121.                 (char_u *)&p_inf, PV_INF,
  1122.                 {(char_u *)FALSE, (char_u *)0L}},
  1123.     {"insertmode",  "im",   P_BOOL|P_VI_DEF|P_VIM,
  1124.                 (char_u *)&p_im, PV_NONE,
  1125.                 {(char_u *)FALSE, (char_u *)0L}},
  1126.     {"isfname",        "isf",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1127.                 (char_u *)&p_isf, PV_NONE,
  1128.                 {
  1129. #ifdef BACKSLASH_IN_FILENAME
  1130.                 /* Excluded are: & and ^ are special in cmd.exe
  1131.                  * ( and ) are used in text separating fnames */
  1132.                 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
  1133. #else
  1134. # ifdef AMIGA
  1135.                 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
  1136. # else
  1137. #  ifdef VMS
  1138.                 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
  1139. #  else /* UNIX et al. */
  1140. #   ifdef EBCDIC
  1141.                 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
  1142. #   else
  1143.                 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
  1144. #   endif
  1145. #  endif
  1146. # endif
  1147. #endif
  1148.                 (char_u *)0L}},
  1149.     {"isident",        "isi",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1150.                 (char_u *)&p_isi, PV_NONE,
  1151.                 {
  1152. #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  1153.                 (char_u *)"@,48-57,_,128-167,224-235",
  1154. #else
  1155. # ifdef EBCDIC
  1156.                 /* TODO: EBCDIC Check this! @ == isalpha()*/
  1157.                 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
  1158.                     "112-120,128,140-142,156,158,172,"
  1159.                     "174,186,191,203-207,219-225,235-239,"
  1160.                     "251-254",
  1161. # else
  1162.                 (char_u *)"@,48-57,_,192-255",
  1163. # endif
  1164. #endif
  1165.                 (char_u *)0L}},
  1166.     {"iskeyword",   "isk",  P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
  1167.                 (char_u *)&p_isk, PV_ISK,
  1168.                 {
  1169. #ifdef EBCDIC
  1170.                  (char_u *)"@,240-249,_",
  1171.                  /* TODO: EBCDIC Check this! @ == isalpha()*/
  1172.                  (char_u *)"@,240-249,_,66-73,81-89,98-105,"
  1173.                     "112-120,128,140-142,156,158,172,"
  1174.                     "174,186,191,203-207,219-225,235-239,"
  1175.                     "251-254",
  1176. #else
  1177.                 (char_u *)"@,48-57,_",
  1178. # if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  1179.                 (char_u *)"@,48-57,_,128-167,224-235"
  1180. # else
  1181.                 (char_u *)"@,48-57,_,192-255"
  1182. # endif
  1183. #endif
  1184.                 }},
  1185.     {"isprint",        "isp",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
  1186.                 (char_u *)&p_isp, PV_NONE,
  1187.                 {
  1188. #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
  1189.         || defined(VMS)
  1190.                 (char_u *)"@,~-255",
  1191. #else
  1192. # ifdef EBCDIC
  1193.                 /* all chars above 63 are printable */
  1194.                 (char_u *)"63-255",
  1195. # else
  1196.                 (char_u *)"@,161-255",
  1197. # endif
  1198. #endif
  1199.                 (char_u *)0L}},
  1200.     {"joinspaces",  "js",   P_BOOL|P_VI_DEF|P_VIM,
  1201.                 (char_u *)&p_js, PV_NONE,
  1202.                 {(char_u *)TRUE, (char_u *)0L}},
  1203.     {"key",        NULL,   P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
  1204. #ifdef FEAT_CRYPT
  1205.                 (char_u *)&p_key, PV_KEY,
  1206.                 {(char_u *)"", (char_u *)0L}
  1207. #else
  1208.                 (char_u *)NULL, PV_NONE,
  1209.                 {(char_u *)0L, (char_u *)0L}
  1210. #endif
  1211.                 },
  1212.     {"keymap",        "kmp",  P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT,
  1213. #ifdef FEAT_KEYMAP
  1214.                 (char_u *)&p_keymap, PV_KMAP,
  1215.                 {(char_u *)"", (char_u *)0L}
  1216. #else
  1217.                 (char_u *)NULL, PV_NONE,
  1218.                 {(char_u *)"", (char_u *)0L}
  1219. #endif
  1220.     },
  1221.     {"keymodel",    "km",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1222. #ifdef FEAT_VISUAL
  1223.                 (char_u *)&p_km, PV_NONE,
  1224. #else
  1225.                 (char_u *)NULL, PV_NONE,
  1226. #endif
  1227.                 {(char_u *)"", (char_u *)0L}},
  1228.     {"keywordprg",  "kp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1229.                 (char_u *)&p_kp, PV_NONE,
  1230.                 {
  1231. #if defined(MSDOS) || defined(MSWIN)
  1232.                 (char_u *)"",
  1233. #else
  1234. #ifdef VMS
  1235.                 (char_u *)"help",
  1236. #else
  1237. # if defined(OS2)
  1238.                 (char_u *)"view /",
  1239. # else
  1240. #  ifdef USEMAN_S
  1241.                 (char_u *)"man -s",
  1242. #  else
  1243.                 (char_u *)"man",
  1244. #  endif
  1245. # endif
  1246. #endif
  1247. #endif
  1248.                 (char_u *)0L}},
  1249.     {"langmap",     "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1250. #ifdef FEAT_LANGMAP
  1251.                 (char_u *)&p_langmap, PV_NONE,
  1252.                 {(char_u *)"",    /* unmatched } */
  1253. #else
  1254.                 (char_u *)NULL, PV_NONE,
  1255.                 {(char_u *)NULL,
  1256. #endif
  1257.                 (char_u *)0L}},
  1258.     {"langmenu",    "lm",   P_STRING|P_VI_DEF,
  1259. #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
  1260.                 (char_u *)&p_lm, PV_NONE,
  1261. #else
  1262.                 (char_u *)NULL, PV_NONE,
  1263. #endif
  1264.                 {(char_u *)"", (char_u *)0L}},
  1265.     {"laststatus",  "ls",   P_NUM|P_VI_DEF|P_RALL,
  1266. #ifdef FEAT_WINDOWS
  1267.                 (char_u *)&p_ls, PV_NONE,
  1268. #else
  1269.                 (char_u *)NULL, PV_NONE,
  1270. #endif
  1271.                 {(char_u *)1L, (char_u *)0L}},
  1272.     {"lazyredraw",  "lz",   P_BOOL|P_VI_DEF,
  1273.                 (char_u *)&p_lz, PV_NONE,
  1274.                 {(char_u *)FALSE, (char_u *)0L}},
  1275.     {"linebreak",   "lbr",  P_BOOL|P_VI_DEF|P_RWIN,
  1276. #ifdef FEAT_LINEBREAK
  1277.                 (char_u *)VAR_WIN, PV_LBR,
  1278. #else
  1279.                 (char_u *)NULL, PV_NONE,
  1280. #endif
  1281.                 {(char_u *)FALSE, (char_u *)0L}},
  1282.     {"lines",        NULL,   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
  1283.                 (char_u *)&Rows, PV_NONE,
  1284.                 {
  1285. #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
  1286.                 (char_u *)25L,
  1287. #else
  1288.                 (char_u *)24L,
  1289. #endif
  1290.                         (char_u *)0L}},
  1291.     {"linespace",   "lsp",  P_NUM|P_VI_DEF|P_RCLR,
  1292. #ifdef FEAT_GUI
  1293.                 (char_u *)&p_linespace, PV_NONE,
  1294. #else
  1295.                 (char_u *)NULL, PV_NONE,
  1296. #endif
  1297. #ifdef FEAT_GUI_W32
  1298.                 {(char_u *)1L, (char_u *)0L}
  1299. #else
  1300.                 {(char_u *)0L, (char_u *)0L}
  1301. #endif
  1302.                 },
  1303.     {"lisp",        NULL,   P_BOOL|P_VI_DEF,
  1304. #ifdef FEAT_LISP
  1305.                 (char_u *)&p_lisp, PV_LISP,
  1306. #else
  1307.                 (char_u *)NULL, PV_NONE,
  1308. #endif
  1309.                 {(char_u *)FALSE, (char_u *)0L}},
  1310.     {"lispwords",   "lw",   P_STRING|P_VI_DEF,
  1311. #ifdef FEAT_LISP
  1312.                 (char_u *)&p_lispwords, PV_NONE,
  1313.                 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
  1314. #else
  1315.                 (char_u *)NULL, PV_NONE,
  1316.                 {(char_u *)"", (char_u *)0L}
  1317. #endif
  1318.                 },
  1319.     {"list",        NULL,   P_BOOL|P_VI_DEF|P_RWIN,
  1320.                 (char_u *)VAR_WIN, PV_LIST,
  1321.                 {(char_u *)FALSE, (char_u *)0L}},
  1322.     {"listchars",   "lcs",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
  1323.                 (char_u *)&p_lcs, PV_NONE,
  1324.                 {(char_u *)"eol:$", (char_u *)0L}},
  1325.     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
  1326.                 (char_u *)&p_lpl, PV_NONE,
  1327.                 {(char_u *)TRUE, (char_u *)0L}},
  1328.     {"magic",        NULL,   P_BOOL|P_VI_DEF,
  1329.                 (char_u *)&p_magic, PV_NONE,
  1330.                 {(char_u *)TRUE, (char_u *)0L}},
  1331.     {"makeef",        "mef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1332. #ifdef FEAT_QUICKFIX
  1333.                 (char_u *)&p_mef, PV_NONE,
  1334.                 {(char_u *)"", (char_u *)0L}
  1335. #else
  1336.                 (char_u *)NULL, PV_NONE,
  1337.                 {(char_u *)NULL, (char_u *)0L}
  1338. #endif
  1339.                 },
  1340.     {"makeprg",        "mp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1341. #ifdef FEAT_QUICKFIX
  1342.                 (char_u *)&p_mp, OPT_BOTH(PV_MP),
  1343. # ifdef VMS
  1344.                 {(char_u *)"MMS", (char_u *)0L}
  1345. # else
  1346.                 {(char_u *)"make", (char_u *)0L}
  1347. # endif
  1348. #else
  1349.                 (char_u *)NULL, PV_NONE,
  1350.                 {(char_u *)NULL, (char_u *)0L}
  1351. #endif
  1352.                 },
  1353.     {"matchpairs",  "mps",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  1354.                 (char_u *)&p_mps, PV_MPS,
  1355.                 {(char_u *)"(:),{:},[:]", (char_u *)0L}},
  1356.     {"matchtime",   "mat",  P_NUM|P_VI_DEF,
  1357.                 (char_u *)&p_mat, PV_NONE,
  1358.                 {(char_u *)5L, (char_u *)0L}},
  1359.     {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
  1360. #ifdef FEAT_EVAL
  1361.                 (char_u *)&p_mfd, PV_NONE,
  1362. #else
  1363.                 (char_u *)NULL, PV_NONE,
  1364. #endif
  1365.                 {(char_u *)100L, (char_u *)0L}},
  1366.     {"maxmapdepth", "mmd",  P_NUM|P_VI_DEF,
  1367.                 (char_u *)&p_mmd, PV_NONE,
  1368.                 {(char_u *)1000L, (char_u *)0L}},
  1369.     {"maxmem",        "mm",   P_NUM|P_VI_DEF,
  1370.                 (char_u *)&p_mm, PV_NONE,
  1371.                 {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
  1372.     {"maxmemtot",   "mmt",  P_NUM|P_VI_DEF,
  1373.                 (char_u *)&p_mmt, PV_NONE,
  1374.                 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
  1375.     {"menuitems",   "mis",  P_NUM|P_VI_DEF,
  1376. #ifdef FEAT_MENU
  1377.                 (char_u *)&p_mis, PV_NONE,
  1378. #else
  1379.                 (char_u *)NULL, PV_NONE,
  1380. #endif
  1381.                 {(char_u *)25L, (char_u *)0L}},
  1382.     {"mesg",        NULL,   P_BOOL|P_VI_DEF,
  1383.                 (char_u *)NULL, PV_NONE,
  1384.                 {(char_u *)FALSE, (char_u *)0L}},
  1385.     {"modeline",    "ml",   P_BOOL|P_VIM,
  1386.                 (char_u *)&p_ml, PV_ML,
  1387.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1388.     {"modelines",   "mls",  P_NUM|P_VI_DEF,
  1389.                 (char_u *)&p_mls, PV_NONE,
  1390.                 {(char_u *)5L, (char_u *)0L}},
  1391.     {"modifiable",  "ma",   P_BOOL|P_VI_DEF,
  1392.                 (char_u *)&p_ma, PV_MA,
  1393.                 {(char_u *)TRUE, (char_u *)0L}},
  1394.     {"modified",    "mod",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
  1395.                 (char_u *)&p_mod, PV_MOD,
  1396.                 {(char_u *)FALSE, (char_u *)0L}},
  1397.     {"more",        NULL,   P_BOOL|P_VIM,
  1398.                 (char_u *)&p_more, PV_NONE,
  1399.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1400.     {"mouse",        NULL,   P_STRING|P_VI_DEF|P_FLAGLIST,
  1401.                 (char_u *)&p_mouse, PV_NONE,
  1402.                 {
  1403. #if defined(MSDOS) || defined(WIN3264)
  1404.                 (char_u *)"a",
  1405. #else
  1406.                 (char_u *)"",
  1407. #endif
  1408.                 (char_u *)0L}},
  1409.     {"mousefocus",   "mousef", P_BOOL|P_VI_DEF,
  1410. #ifdef FEAT_GUI
  1411.                 (char_u *)&p_mousef, PV_NONE,
  1412. #else
  1413.                 (char_u *)NULL, PV_NONE,
  1414. #endif
  1415.                 {(char_u *)FALSE, (char_u *)0L}},
  1416.     {"mousehide",   "mh",   P_BOOL|P_VI_DEF,
  1417. #ifdef FEAT_GUI
  1418.                 (char_u *)&p_mh, PV_NONE,
  1419. #else
  1420.                 (char_u *)NULL, PV_NONE,
  1421. #endif
  1422.                 {(char_u *)TRUE, (char_u *)0L}},
  1423.     {"mousemodel",  "mousem", P_STRING|P_VI_DEF,
  1424.                 (char_u *)&p_mousem, PV_NONE,
  1425.                 {
  1426. #if defined(MSDOS) || defined(MSWIN)
  1427.                 (char_u *)"popup",
  1428. #else
  1429. # if defined(MACOS)
  1430.                 (char_u *)"popup_setpos",
  1431. # else
  1432.                 (char_u *)"extend",
  1433. # endif
  1434. #endif
  1435.                 (char_u *)0L}},
  1436.     {"mouseshape",  "mouses",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1437. #ifdef FEAT_MOUSESHAPE
  1438.                 (char_u *)&p_mouseshape, PV_NONE,
  1439.                 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,v:rightup-arrow", (char_u *)0L}
  1440. #else
  1441.                 (char_u *)NULL, PV_NONE,
  1442.                 {(char_u *)NULL, (char_u *)0L}
  1443. #endif
  1444.                 },
  1445.     {"mousetime",   "mouset",    P_NUM|P_VI_DEF,
  1446.                 (char_u *)&p_mouset, PV_NONE,
  1447.                 {(char_u *)500L, (char_u *)0L}},
  1448.     {"novice",        NULL,   P_BOOL|P_VI_DEF,
  1449.                 (char_u *)NULL, PV_NONE,
  1450.                 {(char_u *)FALSE, (char_u *)0L}},
  1451.     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
  1452.                 (char_u *)&p_nf, PV_NF,
  1453.                 {(char_u *)"octal,hex", (char_u *)0L}},
  1454.     {"number",        "nu",   P_BOOL|P_VI_DEF|P_RWIN,
  1455.                 (char_u *)VAR_WIN, PV_NU,
  1456.                 {(char_u *)FALSE, (char_u *)0L}},
  1457.     {"open",        NULL,   P_BOOL|P_VI_DEF,
  1458.                 (char_u *)NULL, PV_NONE,
  1459.                 {(char_u *)FALSE, (char_u *)0L}},
  1460.     {"optimize",    "opt",  P_BOOL|P_VI_DEF,
  1461.                 (char_u *)NULL, PV_NONE,
  1462.                 {(char_u *)FALSE, (char_u *)0L}},
  1463.     {"osfiletype",  "oft",  P_STRING|P_ALLOCED|P_VI_DEF,
  1464. #ifdef FEAT_OSFILETYPE
  1465.                 (char_u *)&p_oft, PV_OFT,
  1466.                 {(char_u *)DFLT_OFT, (char_u *)0L}
  1467. #else
  1468.                 (char_u *)NULL, PV_NONE,
  1469.                 {(char_u *)0L, (char_u *)0L}
  1470. #endif
  1471.                 },
  1472.     {"paragraphs",  "para", P_STRING|P_VI_DEF,
  1473.                 (char_u *)&p_para, PV_NONE,
  1474.                 {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
  1475.     {"paste",        NULL,   P_BOOL|P_VI_DEF,
  1476.                 (char_u *)&p_paste, PV_NONE,
  1477.                 {(char_u *)FALSE, (char_u *)0L}},
  1478.     {"pastetoggle", "pt",   P_STRING|P_VI_DEF,
  1479.                 (char_u *)&p_pt, PV_NONE,
  1480.                 {(char_u *)"", (char_u *)0L}},
  1481.     {"patchexpr",   "pex",  P_STRING|P_VI_DEF|P_SECURE,
  1482. #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
  1483.                 (char_u *)&p_pex, PV_NONE,
  1484.                 {(char_u *)"", (char_u *)0L}
  1485. #else
  1486.                 (char_u *)NULL, PV_NONE,
  1487.                 {(char_u *)0L, (char_u *)0L}
  1488. #endif
  1489.                 },
  1490.     {"patchmode",   "pm",   P_STRING|P_VI_DEF,
  1491.                 (char_u *)&p_pm, PV_NONE,
  1492.                 {(char_u *)"", (char_u *)0L}},
  1493.     {"path",        "pa",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  1494.                 (char_u *)&p_path, OPT_BOTH(PV_PATH),
  1495.                 {
  1496. #if defined AMIGA || defined MSDOS || defined MSWIN
  1497.                 (char_u *)".,,",
  1498. #else
  1499. # if defined(__EMX__)
  1500.                 (char_u *)".,/emx/include,,",
  1501. # else /* Unix, probably */
  1502.                 (char_u *)".,/usr/include,,",
  1503. # endif
  1504. #endif
  1505.                 (char_u *)0L}},
  1506.     {"previewheight", "pvh",P_NUM|P_VI_DEF,
  1507. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  1508.                 (char_u *)&p_pvh, PV_NONE,
  1509. #else
  1510.                 (char_u *)NULL, PV_NONE,
  1511. #endif
  1512.                 {(char_u *)12L, (char_u *)0L}},
  1513.     {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT,
  1514. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  1515.                 (char_u *)VAR_WIN, PV_PVW,
  1516. #else
  1517.                 (char_u *)NULL, PV_NONE,
  1518. #endif
  1519.                 {(char_u *)FALSE, (char_u *)0L}},
  1520.     {"printdevice", "pdev", P_STRING|P_VI_DEF,
  1521. #ifdef FEAT_PRINTER
  1522.                 (char_u *)&p_pdev, PV_NONE,
  1523.                 {(char_u *)"", (char_u *)0L}
  1524. #else
  1525.                 (char_u *)NULL, PV_NONE,
  1526.                 {(char_u *)NULL, (char_u *)0L}
  1527. #endif
  1528.                 },
  1529.     {"printexpr", "pexpr",  P_STRING|P_VI_DEF,
  1530. #ifdef FEAT_POSTSCRIPT
  1531.                 (char_u *)&p_pexpr, PV_NONE,
  1532.                 {(char_u *)"", (char_u *)0L}
  1533. #else
  1534.                 (char_u *)NULL, PV_NONE,
  1535.                 {(char_u *)NULL, (char_u *)0L}
  1536. #endif
  1537.                 },
  1538.     {"printfont", "pfn",    P_STRING|P_VI_DEF,
  1539. #ifdef FEAT_PRINTER
  1540.                 (char_u *)&p_pfn, PV_NONE,
  1541.                 {
  1542. # ifdef MSWIN
  1543.                 (char_u *)"Courier_New:h10",
  1544. # else
  1545.                 (char_u *)"courier",
  1546. # endif
  1547.                 (char_u *)0L}
  1548. #else
  1549.                 (char_u *)NULL, PV_NONE,
  1550.                 {(char_u *)NULL, (char_u *)0L}
  1551. #endif
  1552.                 },
  1553.     {"printheader", "pheader",  P_STRING|P_VI_DEF,
  1554. #ifdef FEAT_PRINTER
  1555.                 (char_u *)&p_header, PV_NONE,
  1556.                 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
  1557. #else
  1558.                 (char_u *)NULL, PV_NONE,
  1559.                 {(char_u *)NULL, (char_u *)0L}
  1560. #endif
  1561.                 },
  1562.     {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1563. #ifdef FEAT_PRINTER
  1564.                 (char_u *)&p_popt, PV_NONE,
  1565.                 {(char_u *)"", (char_u *)0L}
  1566. #else
  1567.                 (char_u *)NULL, PV_NONE,
  1568.                 {(char_u *)NULL, (char_u *)0L}
  1569. #endif
  1570.                 },
  1571.     {"prompt",        NULL,   P_BOOL|P_VI_DEF,
  1572.                 (char_u *)NULL, PV_NONE,
  1573.                 {(char_u *)FALSE, (char_u *)0L}},
  1574.     {"readonly",    "ro",   P_BOOL|P_VI_DEF|P_RSTAT,
  1575.                 (char_u *)&p_ro, PV_RO,
  1576.                 {(char_u *)FALSE, (char_u *)0L}},
  1577.     {"redraw",        NULL,   P_BOOL|P_VI_DEF,
  1578.                 (char_u *)NULL, PV_NONE,
  1579.                 {(char_u *)FALSE, (char_u *)0L}},
  1580.     {"remap",        NULL,   P_BOOL|P_VI_DEF,
  1581.                 (char_u *)&p_remap, PV_NONE,
  1582.                 {(char_u *)TRUE, (char_u *)0L}},
  1583.     {"report",        NULL,   P_NUM|P_VI_DEF,
  1584.                 (char_u *)&p_report, PV_NONE,
  1585.                 {(char_u *)2L, (char_u *)0L}},
  1586.     {"restorescreen", "rs", P_BOOL|P_VI_DEF,
  1587. #ifdef WIN3264
  1588.                 (char_u *)&p_rs, PV_NONE,
  1589. #else
  1590.                 (char_u *)NULL, PV_NONE,
  1591. #endif
  1592.                 {(char_u *)TRUE, (char_u *)0L}},
  1593.     {"revins",        "ri",   P_BOOL|P_VI_DEF|P_VIM,
  1594. #ifdef FEAT_RIGHTLEFT
  1595.                 (char_u *)&p_ri, PV_NONE,
  1596. #else
  1597.                 (char_u *)NULL, PV_NONE,
  1598. #endif
  1599.                 {(char_u *)FALSE, (char_u *)0L}},
  1600.     {"rightleft",   "rl",   P_BOOL|P_VI_DEF|P_RWIN,
  1601. #ifdef FEAT_RIGHTLEFT
  1602.                 (char_u *)VAR_WIN, PV_RL,
  1603. #else
  1604.                 (char_u *)NULL, PV_NONE,
  1605. #endif
  1606.                 {(char_u *)FALSE, (char_u *)0L}},
  1607.     {"ruler",        "ru",   P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
  1608. #ifdef FEAT_CMDL_INFO
  1609.                 (char_u *)&p_ru, PV_NONE,
  1610. #else
  1611.                 (char_u *)NULL, PV_NONE,
  1612. #endif
  1613.                 {(char_u *)FALSE, (char_u *)0L}},
  1614.     {"rulerformat", "ruf",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
  1615. #ifdef FEAT_STL_OPT
  1616.                 (char_u *)&p_ruf, PV_NONE,
  1617. #else
  1618.                 (char_u *)NULL, PV_NONE,
  1619. #endif
  1620.                 {(char_u *)"", (char_u *)0L}},
  1621.     {"runtimepath", "rtp",  P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
  1622.                 (char_u *)&p_rtp, PV_NONE,
  1623.                 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
  1624.     {"scroll",        "scr",  P_NUM|P_NO_MKRC|P_VI_DEF,
  1625.                 (char_u *)VAR_WIN, PV_SCROLL,
  1626.                 {(char_u *)12L, (char_u *)0L}},
  1627.     {"scrollbind",  "scb",  P_BOOL|P_VI_DEF,
  1628. #ifdef FEAT_SCROLLBIND
  1629.                 (char_u *)VAR_WIN, PV_SCBIND,
  1630. #else
  1631.                 (char_u *)NULL, PV_NONE,
  1632. #endif
  1633.                 {(char_u *)FALSE, (char_u *)0L}},
  1634.     {"scrolljump",  "sj",   P_NUM|P_VI_DEF|P_VIM,
  1635.                 (char_u *)&p_sj, PV_NONE,
  1636.                 {(char_u *)1L, (char_u *)0L}},
  1637.     {"scrolloff",   "so",   P_NUM|P_VI_DEF|P_VIM|P_RALL,
  1638.                 (char_u *)&p_so, PV_NONE,
  1639.                 {(char_u *)0L, (char_u *)0L}},
  1640.     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1641. #ifdef FEAT_SCROLLBIND
  1642.                 (char_u *)&p_sbo, PV_NONE,
  1643. #else
  1644.                 (char_u *)NULL, PV_NONE,
  1645. #endif
  1646.                 {(char_u *)"ver,jump", (char_u *)0L}},
  1647.     {"sections",    "sect", P_STRING|P_VI_DEF,
  1648.                 (char_u *)&p_sections, PV_NONE,
  1649.                 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
  1650.     {"secure",        NULL,   P_BOOL|P_VI_DEF|P_SECURE,
  1651.                 (char_u *)&p_secure, PV_NONE,
  1652.                 {(char_u *)FALSE, (char_u *)0L}},
  1653.     {"selection",   "sel",  P_STRING|P_VI_DEF,
  1654. #ifdef FEAT_VISUAL
  1655.                 (char_u *)&p_sel, PV_NONE,
  1656. #else
  1657.                 (char_u *)NULL, PV_NONE,
  1658. #endif
  1659.                 {(char_u *)"inclusive", (char_u *)0L}},
  1660.     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1661. #ifdef FEAT_VISUAL
  1662.                 (char_u *)&p_slm, PV_NONE,
  1663. #else
  1664.                 (char_u *)NULL, PV_NONE,
  1665. #endif
  1666.                 {(char_u *)"", (char_u *)0L}},
  1667.     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1668. #ifdef FEAT_SESSION
  1669.                 (char_u *)&p_ssop, PV_NONE,
  1670.          {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
  1671.                                    (char_u *)0L}
  1672. #else
  1673.                 (char_u *)NULL, PV_NONE,
  1674.                 {(char_u *)0L, (char_u *)0L}
  1675. #endif
  1676.                 },
  1677.     {"shell",        "sh",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  1678.                 (char_u *)&p_sh, PV_NONE,
  1679.                 {
  1680. #ifdef VMS
  1681.                 (char_u *)"-",
  1682. #else
  1683. # if defined(MSDOS)
  1684.                 (char_u *)"command",
  1685. # else
  1686. #  if defined(WIN16)
  1687.                 (char_u *)"command.com",
  1688. #  else
  1689. #   if defined(WIN3264)
  1690.                 (char_u *)"",    /* set in set_init_1() */
  1691. #   else
  1692. #    if defined(OS2)
  1693.                 (char_u *)"cmd.exe",
  1694. #    else
  1695. #     if defined(ARCHIE)
  1696.                 (char_u *)"gos",
  1697. #     else
  1698.                 (char_u *)"sh",
  1699. #     endif
  1700. #    endif
  1701. #   endif
  1702. #  endif
  1703. # endif
  1704. #endif /* VMS */
  1705.                 (char_u *)0L}},
  1706.     {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
  1707.                 (char_u *)&p_shcf, PV_NONE,
  1708.                 {
  1709. #if defined(MSDOS) || defined(MSWIN)
  1710.                 (char_u *)"/c",
  1711. #else
  1712. # if defined(OS2)
  1713.                 (char_u *)"/c",
  1714. # else
  1715.                 (char_u *)"-c",
  1716. # endif
  1717. #endif
  1718.                 (char_u *)0L}},
  1719.     {"shellpipe",   "sp",   P_STRING|P_VI_DEF|P_SECURE,
  1720. #ifdef FEAT_QUICKFIX
  1721.                 (char_u *)&p_sp, PV_NONE,
  1722.                 {
  1723. #if defined(UNIX) || defined(OS2)
  1724. # ifdef ARCHIE
  1725.                 (char_u *)"2>",
  1726. # else
  1727.                 (char_u *)"| tee",
  1728. # endif
  1729. #else
  1730.                 (char_u *)">",
  1731. #endif
  1732.                 (char_u *)0L}
  1733. #else
  1734.                 (char_u *)NULL, PV_NONE,
  1735.                 {(char_u *)0L, (char_u *)0L}
  1736. #endif
  1737.     },
  1738.     {"shellquote",  "shq",  P_STRING|P_VI_DEF|P_SECURE,
  1739.                 (char_u *)&p_shq, PV_NONE,
  1740.                 {(char_u *)"", (char_u *)0L}},
  1741.     {"shellredir",  "srr",  P_STRING|P_VI_DEF|P_SECURE,
  1742.                 (char_u *)&p_srr, PV_NONE,
  1743.                 {(char_u *)">", (char_u *)0L}},
  1744.     {"shellslash",  "ssl",   P_BOOL|P_VI_DEF,
  1745. #ifdef BACKSLASH_IN_FILENAME
  1746.                 (char_u *)&p_ssl, PV_NONE,
  1747. #else
  1748.                 (char_u *)NULL, PV_NONE,
  1749. #endif
  1750.                 {(char_u *)FALSE, (char_u *)0L}},
  1751.     {"shelltype",   "st",   P_NUM|P_VI_DEF,
  1752. #ifdef AMIGA
  1753.                 (char_u *)&p_st, PV_NONE,
  1754. #else
  1755.                 (char_u *)NULL, PV_NONE,
  1756. #endif
  1757.                 {(char_u *)0L, (char_u *)0L}},
  1758.     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
  1759.                 (char_u *)&p_sxq, PV_NONE,
  1760.                 {
  1761. #if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
  1762.                 (char_u *)"\"",
  1763. #else
  1764.                 (char_u *)"",
  1765. #endif
  1766.                 (char_u *)0L}},
  1767.     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
  1768.                 (char_u *)&p_sr, PV_NONE,
  1769.                 {(char_u *)FALSE, (char_u *)0L}},
  1770.     {"shiftwidth",  "sw",   P_NUM|P_VI_DEF,
  1771.                 (char_u *)&p_sw, PV_SW,
  1772.                 {(char_u *)8L, (char_u *)0L}},
  1773.     {"shortmess",   "shm",  P_STRING|P_VIM|P_FLAGLIST,
  1774.                 (char_u *)&p_shm, PV_NONE,
  1775.                 {(char_u *)"", (char_u *)"filnxtToO"}},
  1776.     {"shortname",   "sn",   P_BOOL|P_VI_DEF,
  1777. #ifdef SHORT_FNAME
  1778.                 (char_u *)NULL, PV_NONE,
  1779. #else
  1780.                 (char_u *)&p_sn, PV_SN,
  1781. #endif
  1782.                 {(char_u *)FALSE, (char_u *)0L}},
  1783.     {"showbreak",   "sbr",  P_STRING|P_VI_DEF|P_RALL,
  1784. #ifdef FEAT_LINEBREAK
  1785.                 (char_u *)&p_sbr, PV_NONE,
  1786. #else
  1787.                 (char_u *)NULL, PV_NONE,
  1788. #endif
  1789.                 {(char_u *)"", (char_u *)0L}},
  1790.     {"showcmd",        "sc",   P_BOOL|P_VIM,
  1791. #ifdef FEAT_CMDL_INFO
  1792.                 (char_u *)&p_sc, PV_NONE,
  1793. #else
  1794.                 (char_u *)NULL, PV_NONE,
  1795. #endif
  1796.                 {(char_u *)FALSE,
  1797. #ifdef UNIX
  1798.                 (char_u *)FALSE
  1799. #else
  1800.                 (char_u *)TRUE
  1801. #endif
  1802.                 }},
  1803.     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
  1804.                 (char_u *)&p_sft, PV_NONE,
  1805.                 {(char_u *)FALSE, (char_u *)0L}},
  1806.     {"showmatch",   "sm",   P_BOOL|P_VI_DEF,
  1807.                 (char_u *)&p_sm, PV_NONE,
  1808.                 {(char_u *)FALSE, (char_u *)0L}},
  1809.     {"showmode",    "smd",  P_BOOL|P_VIM,
  1810.                 (char_u *)&p_smd, PV_NONE,
  1811.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1812.     {"sidescroll",  "ss",   P_NUM|P_VI_DEF,
  1813.                 (char_u *)&p_ss, PV_NONE,
  1814.                 {(char_u *)0L, (char_u *)0L}},
  1815.     {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
  1816.                 (char_u *)&p_siso, PV_NONE,
  1817.                 {(char_u *)0L, (char_u *)0L}},
  1818.     {"slowopen",    "slow", P_BOOL|P_VI_DEF,
  1819.                 (char_u *)NULL, PV_NONE,
  1820.                 {(char_u *)FALSE, (char_u *)0L}},
  1821.     {"smartcase",   "scs",  P_BOOL|P_VI_DEF|P_VIM,
  1822.                 (char_u *)&p_scs, PV_NONE,
  1823.                 {(char_u *)FALSE, (char_u *)0L}},
  1824.     {"smartindent", "si",   P_BOOL|P_VI_DEF|P_VIM,
  1825. #ifdef FEAT_SMARTINDENT
  1826.                 (char_u *)&p_si, PV_SI,
  1827. #else
  1828.                 (char_u *)NULL, PV_NONE,
  1829. #endif
  1830.                 {(char_u *)FALSE, (char_u *)0L}},
  1831.     {"smarttab",    "sta",  P_BOOL|P_VI_DEF|P_VIM,
  1832.                 (char_u *)&p_sta, PV_NONE,
  1833.                 {(char_u *)FALSE, (char_u *)0L}},
  1834.     {"softtabstop", "sts",  P_NUM|P_VI_DEF|P_VIM,
  1835.                 (char_u *)&p_sts, PV_STS,
  1836.                 {(char_u *)0L, (char_u *)0L}},
  1837.     {"sourceany",   NULL,   P_BOOL|P_VI_DEF,
  1838.                 (char_u *)NULL, PV_NONE,
  1839.                 {(char_u *)FALSE, (char_u *)0L}},
  1840.     {"splitbelow",  "sb",   P_BOOL|P_VI_DEF,
  1841. #ifdef FEAT_WINDOWS
  1842.                 (char_u *)&p_sb, PV_NONE,
  1843. #else
  1844.                 (char_u *)NULL, PV_NONE,
  1845. #endif
  1846.                 {(char_u *)FALSE, (char_u *)0L}},
  1847.     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
  1848. #ifdef FEAT_VERTSPLIT
  1849.                 (char_u *)&p_spr, PV_NONE,
  1850. #else
  1851.                 (char_u *)NULL, PV_NONE,
  1852. #endif
  1853.                 {(char_u *)FALSE, (char_u *)0L}},
  1854.     {"startofline", "sol",  P_BOOL|P_VI_DEF|P_VIM,
  1855.                 (char_u *)&p_sol, PV_NONE,
  1856.                 {(char_u *)TRUE, (char_u *)0L}},
  1857.     {"statusline"  ,"stl",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
  1858. #ifdef FEAT_STL_OPT
  1859.                 (char_u *)&p_stl, PV_NONE,
  1860. #else
  1861.                 (char_u *)NULL, PV_NONE,
  1862. #endif
  1863.                 {(char_u *)"", (char_u *)0L}},
  1864.     {"suffixes",    "su",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1865.                 (char_u *)&p_su, PV_NONE,
  1866.                 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
  1867.                 (char_u *)0L}},
  1868.     {"suffixesadd", "sua",  P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
  1869. #if defined(FEAT_SEARCHPATH)
  1870.                 (char_u *)&p_sua, PV_SUA,
  1871.                 {(char_u *)"", (char_u *)0L}
  1872. #else
  1873.                 (char_u *)NULL, PV_NONE,
  1874.                 {(char_u *)0L, (char_u *)0L}
  1875. #endif
  1876.                 },
  1877.     {"swapfile",    "swf",  P_BOOL|P_VI_DEF|P_RSTAT,
  1878.                 (char_u *)&p_swf, PV_SWF,
  1879.                 {(char_u *)TRUE, (char_u *)0L}},
  1880.     {"swapsync",    "sws",  P_STRING|P_VI_DEF,
  1881.                 (char_u *)&p_sws, PV_NONE,
  1882.                 {(char_u *)"fsync", (char_u *)0L}},
  1883.     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  1884.                 (char_u *)&p_swb, PV_NONE,
  1885.                 {(char_u *)"", (char_u *)0L}},
  1886.     {"syntax",        "syn",  P_STRING|P_ALLOCED|P_VI_DEF,
  1887. #ifdef FEAT_SYN_HL
  1888.                 (char_u *)&p_syn, PV_SYN,
  1889.                 {(char_u *)"", (char_u *)0L}
  1890. #else
  1891.                 (char_u *)NULL, PV_NONE,
  1892.                 {(char_u *)0L, (char_u *)0L}
  1893. #endif
  1894.                 },
  1895.     {"tabstop",        "ts",   P_NUM|P_VI_DEF|P_RBUF,
  1896.                 (char_u *)&p_ts, PV_TS,
  1897.                 {(char_u *)8L, (char_u *)0L}},
  1898.     {"tagbsearch",  "tbs",   P_BOOL|P_VI_DEF,
  1899.                 (char_u *)&p_tbs, PV_NONE,
  1900. #ifdef VMS    /* binary searching doesn't appear to work on VMS */
  1901.                 {(char_u *)0L, (char_u *)0L}},
  1902. #else
  1903.                 {(char_u *)TRUE, (char_u *)0L}},
  1904. #endif
  1905.     {"taglength",   "tl",   P_NUM|P_VI_DEF,
  1906.                 (char_u *)&p_tl, PV_NONE,
  1907.                 {(char_u *)0L, (char_u *)0L}},
  1908.     {"tagrelative", "tr",   P_BOOL|P_VIM,
  1909.                 (char_u *)&p_tr, PV_NONE,
  1910.                 {(char_u *)FALSE, (char_u *)TRUE}},
  1911.     {"tags",        "tag",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  1912.                 (char_u *)&p_tags, OPT_BOTH(PV_TAGS),
  1913.                 {
  1914. #ifdef FEAT_EMACS_TAGS
  1915.                 (char_u *)"./tags,./TAGS,tags,TAGS",
  1916. #else
  1917.                 (char_u *)"./tags,tags",
  1918. #endif
  1919.                 (char_u *)0L}},
  1920.     {"tagstack",    "tgst", P_BOOL|P_VI_DEF,
  1921.                 (char_u *)&p_tgst, PV_NONE,
  1922.                 {(char_u *)TRUE, (char_u *)0L}},
  1923.     {"term",        NULL,   P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
  1924.                 (char_u *)&T_NAME, PV_NONE,
  1925.                 {(char_u *)"", (char_u *)0L}},
  1926.     {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
  1927. #ifdef FEAT_MBYTE
  1928.                 (char_u *)&p_tenc, PV_NONE,
  1929.                 {(char_u *)"", (char_u *)0L}
  1930. #else
  1931.                 (char_u *)NULL, PV_NONE,
  1932.                 {(char_u *)0L, (char_u *)0L}
  1933. #endif
  1934.                 },
  1935.     {"terse",        NULL,   P_BOOL|P_VI_DEF,
  1936.                 (char_u *)&p_terse, PV_NONE,
  1937.                 {(char_u *)FALSE, (char_u *)0L}},
  1938.     {"textauto",    "ta",   P_BOOL|P_VIM,
  1939.                 (char_u *)&p_ta, PV_NONE,
  1940.                 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
  1941.     {"textmode",    "tx",   P_BOOL|P_VI_DEF|P_NO_MKRC,
  1942.                 (char_u *)&p_tx, PV_TX,
  1943.                 {
  1944. #ifdef USE_CRNL
  1945.                 (char_u *)TRUE,
  1946. #else
  1947.                 (char_u *)FALSE,
  1948. #endif
  1949.                 (char_u *)0L}},
  1950.     {"textwidth",   "tw",   P_NUM|P_VI_DEF|P_VIM,
  1951.                 (char_u *)&p_tw, PV_TW,
  1952.                 {(char_u *)0L, (char_u *)0L}},
  1953.     {"thesaurus",   "tsr",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
  1954. #ifdef FEAT_INS_EXPAND
  1955.                 (char_u *)&p_tsr, OPT_BOTH(PV_TSR),
  1956. #else
  1957.                 (char_u *)NULL, PV_NONE,
  1958. #endif
  1959.                 {(char_u *)"", (char_u *)0L}},
  1960.     {"tildeop",        "top",  P_BOOL|P_VI_DEF|P_VIM,
  1961.                 (char_u *)&p_to, PV_NONE,
  1962.                 {(char_u *)FALSE, (char_u *)0L}},
  1963.     {"timeout",        "to",   P_BOOL|P_VI_DEF,
  1964.                 (char_u *)&p_timeout, PV_NONE,
  1965.                 {(char_u *)TRUE, (char_u *)0L}},
  1966.     {"timeoutlen",  "tm",   P_NUM|P_VI_DEF,
  1967.                 (char_u *)&p_tm, PV_NONE,
  1968.                 {(char_u *)1000L, (char_u *)0L}},
  1969.     {"title",        NULL,   P_BOOL|P_VI_DEF,
  1970. #ifdef FEAT_TITLE
  1971.                 (char_u *)&p_title, PV_NONE,
  1972. #else
  1973.                 (char_u *)NULL, PV_NONE,
  1974. #endif
  1975.                 {(char_u *)FALSE, (char_u *)0L}},
  1976.     {"titlelen",    NULL,   P_NUM|P_VI_DEF,
  1977. #ifdef FEAT_TITLE
  1978.                 (char_u *)&p_titlelen, PV_NONE,
  1979. #else
  1980.                 (char_u *)NULL, PV_NONE,
  1981. #endif
  1982.                 {(char_u *)85L, (char_u *)0L}},
  1983.     {"titleold",    NULL,   P_STRING|P_VI_DEF,
  1984. #ifdef FEAT_TITLE
  1985.                 (char_u *)&p_titleold, PV_NONE,
  1986. #else
  1987.                 (char_u *)NULL, PV_NONE,
  1988. #endif
  1989.                 {(char_u *)N_("Thanks for flying Vim"),
  1990.                                    (char_u *)0L}},
  1991.     {"titlestring", NULL,   P_STRING|P_VI_DEF,
  1992. #ifdef FEAT_TITLE
  1993.                 (char_u *)&p_titlestring, PV_NONE,
  1994. #else
  1995.                 (char_u *)NULL, PV_NONE,
  1996. #endif
  1997.                 {(char_u *)"", (char_u *)0L}},
  1998. #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
  1999.     {"toolbar",     "tb",   P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
  2000.                 (char_u *)&p_toolbar, PV_NONE,
  2001.                 {(char_u *)"icons,tooltips", (char_u *)0L}},
  2002. #endif
  2003.     {"ttimeout",    NULL,   P_BOOL|P_VI_DEF|P_VIM,
  2004.                 (char_u *)&p_ttimeout, PV_NONE,
  2005.                 {(char_u *)FALSE, (char_u *)0L}},
  2006.     {"ttimeoutlen", "ttm",  P_NUM|P_VI_DEF,
  2007.                 (char_u *)&p_ttm, PV_NONE,
  2008.                 {(char_u *)-1L, (char_u *)0L}},
  2009.     {"ttybuiltin",  "tbi",  P_BOOL|P_VI_DEF,
  2010.                 (char_u *)&p_tbi, PV_NONE,
  2011.                 {(char_u *)TRUE, (char_u *)0L}},
  2012.     {"ttyfast",        "tf",   P_BOOL|P_NO_MKRC|P_VI_DEF,
  2013.                 (char_u *)&p_tf, PV_NONE,
  2014.                 {(char_u *)FALSE, (char_u *)0L}},
  2015.     {"ttymouse",    "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
  2016. #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
  2017.                 (char_u *)&p_ttym, PV_NONE,
  2018. #else
  2019.                 (char_u *)NULL, PV_NONE,
  2020. #endif
  2021.                 {(char_u *)"", (char_u *)0L}},
  2022.     {"ttyscroll",   "tsl",  P_NUM|P_VI_DEF,
  2023.                 (char_u *)&p_ttyscroll, PV_NONE,
  2024.                 {(char_u *)999L, (char_u *)0L}},
  2025.     {"ttytype",        "tty",  P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
  2026.                 (char_u *)&T_NAME, PV_NONE,
  2027.                 {(char_u *)"", (char_u *)0L}},
  2028.     {"undolevels",  "ul",   P_NUM|P_VI_DEF,
  2029.                 (char_u *)&p_ul, PV_NONE,
  2030.                 {
  2031. #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
  2032.                 (char_u *)1000L,
  2033. #else
  2034.                 (char_u *)100L,
  2035. #endif
  2036.                 (char_u *)0L}},
  2037.     {"updatecount", "uc",   P_NUM|P_VI_DEF,
  2038.                 (char_u *)&p_uc, PV_NONE,
  2039.                 {(char_u *)200L, (char_u *)0L}},
  2040.     {"updatetime",  "ut",   P_NUM|P_VI_DEF,
  2041.                 (char_u *)&p_ut, PV_NONE,
  2042.                 {(char_u *)4000L, (char_u *)0L}},
  2043.     {"verbose",        "vbs",  P_NUM|P_VI_DEF,
  2044.                 (char_u *)&p_verbose, PV_NONE,
  2045.                 {(char_u *)0L, (char_u *)0L}},
  2046.     {"viewdir",     "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
  2047. #ifdef FEAT_SESSION
  2048.                 (char_u *)&p_vdir, PV_NONE,
  2049.                 {(char_u *)DFLT_VDIR, (char_u *)0L}
  2050. #else
  2051.                 (char_u *)NULL, PV_NONE,
  2052.                 {(char_u *)0L, (char_u *)0L}
  2053. #endif
  2054.                 },
  2055.     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  2056. #ifdef FEAT_SESSION
  2057.                 (char_u *)&p_vop, PV_NONE,
  2058.                 {(char_u *)"folds,options,cursor", (char_u *)0L}
  2059. #else
  2060.                 (char_u *)NULL, PV_NONE,
  2061.                 {(char_u *)0L, (char_u *)0L}
  2062. #endif
  2063.                 },
  2064.     {"viminfo",        "vi",   P_STRING|P_COMMA|P_NODUP|P_SECURE,
  2065. #ifdef FEAT_VIMINFO
  2066.                 (char_u *)&p_viminfo, PV_NONE,
  2067. #else
  2068.                 (char_u *)NULL, PV_NONE,
  2069. #endif
  2070. #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  2071.                 {(char_u *)"", (char_u *)"'20,\"50,h,rA:,rB:"}
  2072. #else
  2073. # ifdef AMIGA
  2074.                 {(char_u *)"",
  2075.                      (char_u *)"'20,\"50,h,rdf0:,rdf1:,rdf2:"}
  2076. # else
  2077.                 {(char_u *)"", (char_u *)"'20,\"50,h"}
  2078. # endif
  2079. #endif
  2080.     },
  2081.     {"virtualedit", "ve",   P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
  2082. #ifdef FEAT_VIRTUALEDIT
  2083.                 (char_u *)&p_ve, PV_NONE,
  2084.                 {(char_u *)"", (char_u *)""}
  2085. #else
  2086.                 (char_u *)NULL, PV_NONE,
  2087.                 {(char_u *)0L, (char_u *)0L}
  2088. #endif
  2089.                 },
  2090.     {"visualbell",  "vb",   P_BOOL|P_VI_DEF,
  2091.                 (char_u *)&p_vb, PV_NONE,
  2092.                 {(char_u *)FALSE, (char_u *)0L}},
  2093.     {"w300",        NULL,   P_NUM|P_VI_DEF,
  2094.                 (char_u *)NULL, PV_NONE,
  2095.                 {(char_u *)0L, (char_u *)0L}},
  2096.     {"w1200",        NULL,   P_NUM|P_VI_DEF,
  2097.                 (char_u *)NULL, PV_NONE,
  2098.                 {(char_u *)0L, (char_u *)0L}},
  2099.     {"w9600",        NULL,   P_NUM|P_VI_DEF,
  2100.                 (char_u *)NULL, PV_NONE,
  2101.                 {(char_u *)0L, (char_u *)0L}},
  2102.     {"warn",        NULL,   P_BOOL|P_VI_DEF,
  2103.                 (char_u *)&p_warn, PV_NONE,
  2104.                 {(char_u *)TRUE, (char_u *)0L}},
  2105.     {"weirdinvert", "wiv",  P_BOOL|P_VI_DEF|P_RCLR,
  2106.                 (char_u *)&p_wiv, PV_NONE,
  2107.                 {(char_u *)FALSE, (char_u *)0L}},
  2108.     {"whichwrap",   "ww",   P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
  2109.                 (char_u *)&p_ww, PV_NONE,
  2110.                 {(char_u *)"", (char_u *)"b,s"}},
  2111.     {"wildchar",    "wc",   P_NUM|P_VIM,
  2112.                 (char_u *)&p_wc, PV_NONE,
  2113.                 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
  2114.     {"wildcharm",   "wcm",   P_NUM|P_VI_DEF,
  2115.                 (char_u *)&p_wcm, PV_NONE,
  2116.                 {(char_u *)0L, (char_u *)0L}},
  2117.     {"wildignore",  "wig",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  2118. #ifdef FEAT_WILDIGN
  2119.                 (char_u *)&p_wig, PV_NONE,
  2120. #else
  2121.                 (char_u *)NULL, PV_NONE,
  2122. #endif
  2123.                 {(char_u *)"", (char_u *)0L}},
  2124.     {"wildmenu",    "wmnu", P_BOOL|P_VI_DEF,
  2125. #ifdef FEAT_WILDMENU
  2126.                 (char_u *)&p_wmnu, PV_NONE,
  2127. #else
  2128.                 (char_u *)NULL, PV_NONE,
  2129. #endif
  2130.                 {(char_u *)FALSE, (char_u *)0L}},
  2131.     {"wildmode",    "wim",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
  2132.                 (char_u *)&p_wim, PV_NONE,
  2133.                 {(char_u *)"full", (char_u *)0L}},
  2134.     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
  2135. #ifdef FEAT_WAK
  2136.                 (char_u *)&p_wak, PV_NONE,
  2137.                 {(char_u *)"menu", (char_u *)0L}
  2138. #else
  2139.                 (char_u *)NULL, PV_NONE,
  2140.                 {(char_u *)NULL, (char_u *)0L}
  2141. #endif
  2142.                 },
  2143.     {"window",        "wi",   P_NUM|P_VI_DEF,
  2144.                 (char_u *)NULL, PV_NONE,
  2145.                 {(char_u *)0L, (char_u *)0L}},
  2146.     {"winheight",   "wh",   P_NUM|P_VI_DEF,
  2147. #ifdef FEAT_WINDOWS
  2148.                 (char_u *)&p_wh, PV_NONE,
  2149. #else
  2150.                 (char_u *)NULL, PV_NONE,
  2151. #endif
  2152.                 {(char_u *)1L, (char_u *)0L}},
  2153.     {"winminheight", "wmh", P_NUM|P_VI_DEF,
  2154. #ifdef FEAT_WINDOWS
  2155.                 (char_u *)&p_wmh, PV_NONE,
  2156. #else
  2157.                 (char_u *)NULL, PV_NONE,
  2158. #endif
  2159.                 {(char_u *)1L, (char_u *)0L}},
  2160.     {"winminwidth", "wmw", P_NUM|P_VI_DEF,
  2161. #ifdef FEAT_VERTSPLIT
  2162.                 (char_u *)&p_wmw, PV_NONE,
  2163. #else
  2164.                 (char_u *)NULL, PV_NONE,
  2165. #endif
  2166.                 {(char_u *)1L, (char_u *)0L}},
  2167.     {"winwidth",   "wiw",   P_NUM|P_VI_DEF,
  2168. #ifdef FEAT_VERTSPLIT
  2169.                 (char_u *)&p_wiw, PV_NONE,
  2170. #else
  2171.                 (char_u *)NULL, PV_NONE,
  2172. #endif
  2173.                 {(char_u *)20L, (char_u *)0L}},
  2174.     {"wrap",        NULL,   P_BOOL|P_VI_DEF|P_RWIN,
  2175.                 (char_u *)VAR_WIN, PV_WRAP,
  2176.                 {(char_u *)TRUE, (char_u *)0L}},
  2177.     {"wrapmargin",  "wm",   P_NUM|P_VI_DEF,
  2178.                 (char_u *)&p_wm, PV_WM,
  2179.                 {(char_u *)0L, (char_u *)0L}},
  2180.     {"wrapscan",    "ws",   P_BOOL|P_VI_DEF,
  2181.                 (char_u *)&p_ws, PV_NONE,
  2182.                 {(char_u *)TRUE, (char_u *)0L}},
  2183.     {"write",        NULL,   P_BOOL|P_VI_DEF,
  2184.                 (char_u *)&p_write, PV_NONE,
  2185.                 {(char_u *)TRUE, (char_u *)0L}},
  2186.     {"writeany",    "wa",   P_BOOL|P_VI_DEF,
  2187.                 (char_u *)&p_wa, PV_NONE,
  2188.                 {(char_u *)FALSE, (char_u *)0L}},
  2189.     {"writebackup", "wb",   P_BOOL|P_VI_DEF|P_VIM,
  2190.                 (char_u *)&p_wb, PV_NONE,
  2191.                 {
  2192. #ifdef FEAT_WRITEBACKUP
  2193.                 (char_u *)TRUE,
  2194. #else
  2195.                 (char_u *)FALSE,
  2196. #endif
  2197.                 (char_u *)0L}},
  2198.     {"writedelay",  "wd",   P_NUM|P_VI_DEF,
  2199.                 (char_u *)&p_wd, PV_NONE,
  2200.                 {(char_u *)0L, (char_u *)0L}},
  2201.  
  2202. /* terminal output codes */
  2203. #define p_term(sss, vvv)   {sss, NULL, P_STRING|P_VI_DEF|P_RALL, \
  2204.                 (char_u *)&vvv, PV_NONE, \
  2205.                 {(char_u *)"", (char_u *)0L}},
  2206.  
  2207.     p_term("t_AB", T_CAB)
  2208.     p_term("t_AF", T_CAF)
  2209.     p_term("t_AL", T_CAL)
  2210.     p_term("t_al", T_AL)
  2211.     p_term("t_bc", T_BC)
  2212.     p_term("t_cd", T_CD)
  2213.     p_term("t_ce", T_CE)
  2214.     p_term("t_cl", T_CL)
  2215.     p_term("t_cm", T_CM)
  2216.     p_term("t_Co", T_CCO)
  2217.     p_term("t_CS", T_CCS)
  2218.     p_term("t_cs", T_CS)
  2219. #ifdef FEAT_VERTSPLIT
  2220.     p_term("t_CV", T_CSV)
  2221. #endif
  2222.     p_term("t_ut", T_UT)
  2223.     p_term("t_da", T_DA)
  2224.     p_term("t_db", T_DB)
  2225.     p_term("t_DL", T_CDL)
  2226.     p_term("t_dl", T_DL)
  2227.     p_term("t_fs", T_FS)
  2228.     p_term("t_IE", T_CIE)
  2229.     p_term("t_IS", T_CIS)
  2230.     p_term("t_ke", T_KE)
  2231.     p_term("t_ks", T_KS)
  2232.     p_term("t_le", T_LE)
  2233.     p_term("t_mb", T_MB)
  2234.     p_term("t_md", T_MD)
  2235.     p_term("t_me", T_ME)
  2236.     p_term("t_mr", T_MR)
  2237.     p_term("t_ms", T_MS)
  2238.     p_term("t_nd", T_ND)
  2239.     p_term("t_op", T_OP)
  2240.     p_term("t_RI", T_CRI)
  2241.     p_term("t_RV", T_CRV)
  2242.     p_term("t_Sb", T_CSB)
  2243.     p_term("t_Sf", T_CSF)
  2244.     p_term("t_se", T_SE)
  2245.     p_term("t_so", T_SO)
  2246.     p_term("t_sr", T_SR)
  2247.     p_term("t_ts", T_TS)
  2248.     p_term("t_te", T_TE)
  2249.     p_term("t_ti", T_TI)
  2250.     p_term("t_ue", T_UE)
  2251.     p_term("t_us", T_US)
  2252.     p_term("t_vb", T_VB)
  2253.     p_term("t_ve", T_VE)
  2254.     p_term("t_vi", T_VI)
  2255.     p_term("t_vs", T_VS)
  2256.     p_term("t_WP", T_CWP)
  2257.     p_term("t_WS", T_CWS)
  2258.     p_term("t_xs", T_XS)
  2259.     p_term("t_ZH", T_CZH)
  2260.     p_term("t_ZR", T_CZR)
  2261.  
  2262. /* terminal key codes are not in here */
  2263.  
  2264.     {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}}    /* end marker */
  2265. };
  2266.  
  2267. #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
  2268.  
  2269. static char *(p_bg_values[]) = {"light", "dark", NULL};
  2270. static char *(p_bkc_values[]) = {"yes", "auto", "no", NULL};
  2271. static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
  2272. static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
  2273. #ifdef FEAT_WAK
  2274. static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
  2275. #endif
  2276. static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
  2277. #ifdef FEAT_VISUAL
  2278. static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
  2279. static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
  2280. #endif
  2281. #ifdef FEAT_VISUAL
  2282. static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
  2283. #endif
  2284. #ifdef FEAT_BROWSE
  2285. static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
  2286. #endif
  2287. #ifdef FEAT_SCROLLBIND
  2288. static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
  2289. #endif
  2290. static char *(p_swb_values[]) = {"useopen", "split", NULL};
  2291. static char *(p_debug_values[]) = {"msg", NULL};
  2292. #ifdef FEAT_VERTSPLIT
  2293. static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
  2294. #endif
  2295. #if defined(FEAT_QUICKFIX)
  2296. static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
  2297. static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", NULL};
  2298. #endif
  2299. static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
  2300. #ifdef FEAT_FOLDING
  2301. static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
  2302. #ifdef FEAT_DIFF
  2303.                 "diff",
  2304. #endif
  2305.                 NULL};
  2306. static char *(p_fcl_values[]) = {"all", NULL};
  2307. #endif
  2308.  
  2309. static void set_option_default __ARGS((int, int opt_flags, int compatible));
  2310. static void set_options_default __ARGS((int opt_flags));
  2311. static char_u *illegal_char __ARGS((char_u *, int));
  2312. static int string_to_key __ARGS((char_u *arg));
  2313. #ifdef FEAT_CMDWIN
  2314. static char_u *check_cedit __ARGS((void));
  2315. #endif
  2316. #ifdef FEAT_TITLE
  2317. static void did_set_title __ARGS((int icon));
  2318. #endif
  2319. static char_u *option_expand __ARGS((int opt_idx, char_u *val));
  2320. static void didset_options __ARGS((void));
  2321. static void check_string_option __ARGS((char_u **pp));
  2322. static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
  2323. static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
  2324. static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
  2325. static char_u *set_chars_option __ARGS((char_u **varp));
  2326. #ifdef FEAT_CLIPBOARD
  2327. static char_u *check_clipboard_option __ARGS((void));
  2328. #endif
  2329. static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
  2330. static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, int opt_flags));
  2331. static void check_redraw __ARGS((long_u flags));
  2332. static int findoption __ARGS((char_u *));
  2333. static int find_key_option __ARGS((char_u *));
  2334. static void showoptions __ARGS((int all, int opt_flags));
  2335. static int optval_default __ARGS((struct vimoption *, char_u *varp));
  2336. static void showoneopt __ARGS((struct vimoption *, int opt_flags));
  2337. static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
  2338. static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
  2339. static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
  2340. static int  istermoption __ARGS((struct vimoption *));
  2341. static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
  2342. static char_u *get_varp __ARGS((struct vimoption *));
  2343. static void option_value2string __ARGS((struct vimoption *, int opt_flags));
  2344. static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
  2345. #ifdef FEAT_LANGMAP
  2346. static void langmap_init __ARGS((void));
  2347. static void langmap_set __ARGS((void));
  2348. #endif
  2349. static void paste_option_changed __ARGS((void));
  2350. static void compatible_set __ARGS((void));
  2351. #ifdef FEAT_LINEBREAK
  2352. static void fill_breakat_flags __ARGS((void));
  2353. #endif
  2354. static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
  2355. static int check_opt_strings __ARGS((char_u *val, char **values, int));
  2356. static int check_opt_wim __ARGS((void));
  2357.  
  2358. /*
  2359.  * Initialize the options, first part.
  2360.  *
  2361.  * Called only once from main(), just after creating the first buffer.
  2362.  */
  2363.     void
  2364. set_init_1()
  2365. {
  2366.     char_u    *p;
  2367.     int        opt_idx;
  2368.     long    n;
  2369.  
  2370. #ifdef FEAT_LANGMAP
  2371.     langmap_init();
  2372. #endif
  2373.  
  2374.     /* Be Vi compatible by default */
  2375.     p_cp = TRUE;
  2376.  
  2377.     /*
  2378.      * Find default value for 'shell' option.
  2379.      */
  2380.     if ((p = mch_getenv((char_u *)"SHELL")) != NULL
  2381. #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
  2382. # ifdef __EMX__
  2383.         || (p = mch_getenv((char_u *)"EMXSHELL")) != NULL
  2384. # endif
  2385.         || (p = mch_getenv((char_u *)"COMSPEC")) != NULL
  2386. # ifdef WIN3264
  2387.         || (p = default_shell()) != NULL
  2388. # endif
  2389. #endif
  2390.        )
  2391.     set_string_default("sh", p);
  2392.  
  2393. #ifdef FEAT_WILDIGN
  2394.     /*
  2395.      * Set the default for 'backupskip' to include environment variables for
  2396.      * temp files.
  2397.      */
  2398.     {
  2399. # ifdef UNIX
  2400.     static char    *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
  2401. # else
  2402.     static char    *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
  2403. # endif
  2404.     int    len;
  2405.     garray_T ga;
  2406.  
  2407.     ga_init2(&ga, 1, 100);
  2408.     for (n = 0; n < sizeof(names) / sizeof(char *); ++n)
  2409.     {
  2410. # ifdef UNIX
  2411.         if (*names[n] == NUL)
  2412.         p = (char_u *)"/tmp";
  2413.         else
  2414. # endif
  2415.         p = mch_getenv((char_u *)names[n]);
  2416.         if (p != NULL && *p != NUL)
  2417.         {
  2418.         /* First time count the NUL, otherwise count the ','. */
  2419.         len = STRLEN(p) + 3;
  2420.         if (ga_grow(&ga, len) == OK)
  2421.         {
  2422.             if (ga.ga_len > 0)
  2423.             STRCAT(ga.ga_data, ",");
  2424.             STRCAT(ga.ga_data, p);
  2425.             add_pathsep(ga.ga_data);
  2426.             STRCAT(ga.ga_data, "*");
  2427.             ga.ga_room -= len;
  2428.             ga.ga_len += len;
  2429.         }
  2430.         }
  2431.     }
  2432.     if (ga.ga_data != NULL)
  2433.     {
  2434.         set_string_default("bsk", ga.ga_data);
  2435.         vim_free(ga.ga_data);
  2436.     }
  2437.     }
  2438. #endif
  2439.  
  2440.     /*
  2441.      * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
  2442.      */
  2443.     opt_idx = findoption((char_u *)"maxmemtot");
  2444. #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
  2445.     if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
  2446. #endif
  2447.     {
  2448. #ifdef HAVE_AVAIL_MEM
  2449.     /* Use amount of memory available at this moment. */
  2450.     n = (mch_avail_mem(FALSE) >> 11);
  2451. #else
  2452. # ifdef HAVE_TOTAL_MEM
  2453.     /* Use amount of memory available to Vim. */
  2454.     n = (mch_total_mem(FALSE) >> 11);
  2455. # else
  2456.     n = (0x7fffffff >> 11);
  2457. # endif
  2458. #endif
  2459.     options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
  2460.     opt_idx = findoption((char_u *)"maxmem");
  2461. #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
  2462.     if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
  2463.               || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
  2464. #endif
  2465.         options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
  2466.     }
  2467.  
  2468. #ifdef FEAT_GUI_W32
  2469.     /* force 'shortname' for Win32s */
  2470.     if (gui_is_win32s())
  2471.     options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
  2472.                                    (char_u *)TRUE;
  2473. #endif
  2474.  
  2475. #ifdef FEAT_SEARCHPATH
  2476.     {
  2477.     char_u    *cdpath;
  2478.     char_u    *buf;
  2479.     int    i;
  2480.     int    j;
  2481.  
  2482.     /* Initialize the 'cdpath' option's default value. */
  2483.     cdpath = mch_getenv((char_u *)"CDPATH");
  2484.     if (cdpath != NULL)
  2485.     {
  2486.         buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
  2487.         if (buf != NULL)
  2488.         {
  2489.         buf[0] = ',';        /* start with ",", current dir first */
  2490.         j = 1;
  2491.         for (i = 0; cdpath[i] != NUL; ++i)
  2492.         {
  2493.             if (vim_ispathlistsep(cdpath[i]))
  2494.             buf[j++] = ',';
  2495.             else
  2496.             {
  2497.             if (cdpath[i] == ' ' || cdpath[i] == ',')
  2498.                 buf[j++] = '\\';
  2499.             buf[j++] = cdpath[i];
  2500.             }
  2501.         }
  2502.         buf[j] = NUL;
  2503.         opt_idx = findoption((char_u *)"cdpath");
  2504.         options[opt_idx].def_val[VI_DEFAULT] = buf;
  2505.         options[opt_idx].flags |= P_DEF_ALLOCED;
  2506.         }
  2507.     }
  2508.     }
  2509. #endif
  2510.  
  2511. #ifdef FEAT_POSTSCRIPT
  2512.     /* 'printexpr' must be allocated to be able to evaluate it. */
  2513.     set_string_default("pexpr",
  2514. # ifdef MSWIN
  2515.         (char_u *)"system('copy' . ' ' . v:fname_in . ' ' . &printdevice) . delete(v:fname_in)"
  2516. # else
  2517. #  ifdef VMS
  2518.         (char_u *)"system('print' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in)"
  2519.  
  2520. #  else
  2521.         (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
  2522. #  endif
  2523. # endif
  2524.         );
  2525. #endif
  2526.  
  2527.     /*
  2528.      * Set all the options (except the terminal options) to their default
  2529.      * value.  Also set the global value for local options.
  2530.      */
  2531.     set_options_default(0);
  2532.  
  2533. #ifdef FEAT_GUI
  2534.     if (found_reverse_arg)
  2535.     set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
  2536. #endif
  2537.  
  2538.     curbuf->b_p_initialized = TRUE;
  2539.     curbuf->b_p_ar = -1;    /* no local 'autoread' value */
  2540.     check_buf_options(curbuf);
  2541.     check_win_options(curwin);
  2542.     check_options();
  2543.  
  2544.     /* Must be before option_expand(), because that one needs vim_isIDc() */
  2545.     didset_options();
  2546.  
  2547. #ifdef FEAT_LINEBREAK
  2548.     /*
  2549.      * initialize the table for 'breakat'.
  2550.      */
  2551.     fill_breakat_flags();
  2552. #endif
  2553.  
  2554.     /*
  2555.      * Expand environment variables and things like "~" for the defaults.
  2556.      * If option_expand() returns non-NULL the variable is expanded.  This can
  2557.      * only happen for non-indirect options.
  2558.      * Also set the default to the expanded value, so ":set" does not list
  2559.      * them.
  2560.      * Don't set the P_ALLOCED flag, because we don't want to free the
  2561.      * default.
  2562.      */
  2563.     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
  2564.     {
  2565.     p = option_expand(opt_idx, NULL);
  2566.     if (p != NULL && (p = vim_strsave(p)) != NULL)
  2567.     {
  2568.         *(char_u **)options[opt_idx].var = p;
  2569.         /* VIMEXP
  2570.          * Defaults for all expanded options are currently the same for Vi
  2571.          * and Vim.  When this changes, add some code here!  Also need to
  2572.          * split P_DEF_ALLOCED in two.
  2573.          */
  2574.         if (options[opt_idx].flags & P_DEF_ALLOCED)
  2575.         vim_free(options[opt_idx].def_val[VI_DEFAULT]);
  2576.         options[opt_idx].def_val[VI_DEFAULT] = p;
  2577.         options[opt_idx].flags |= P_DEF_ALLOCED;
  2578.     }
  2579.     }
  2580.  
  2581.     /* Initialize the highlight_attr[] table. */
  2582.     highlight_changed();
  2583.  
  2584.     save_file_ff(curbuf);    /* Buffer is unchanged */
  2585.  
  2586.     /* Parse default for 'wildmode'  */
  2587.     check_opt_wim();
  2588.  
  2589. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  2590.     /* Parse default for 'fillchars'. */
  2591.     (void)set_chars_option(&p_fcs);
  2592. #endif
  2593.  
  2594. #ifdef FEAT_CLIPBOARD
  2595.     /* Parse default for 'clipboard' */
  2596.     (void)check_clipboard_option();
  2597. #endif
  2598.  
  2599. #ifdef FEAT_MBYTE
  2600. # if defined(WIN3264) && defined(FEAT_GETTEXT)
  2601.     /*
  2602.      * If $LANG isn't set, try to get a good value for it.  This makes the
  2603.      * right language be used automatically.  Don't do this for English.
  2604.      */
  2605.     if (mch_getenv("LANG") == NULL)
  2606.     {
  2607.     char    buf[20];
  2608.  
  2609.     /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
  2610.      * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
  2611.      * only the first two. */
  2612.     n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
  2613.                                  (LPTSTR)buf, 20);
  2614.     if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
  2615.     {
  2616.         /* There are a few exceptions (probably more) */
  2617.         if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
  2618.         STRCPY(buf, "zh_TW");
  2619.         else if (STRNICMP(buf, "chs", 3) == 0
  2620.                           || STRNICMP(buf, "zhc", 3) == 0)
  2621.         STRCPY(buf, "zh_CN");
  2622.         else if (STRNICMP(buf, "jp", 2) == 0)
  2623.         STRCPY(buf, "ja");
  2624.         else
  2625.         buf[2] = NUL;        /* truncate to two-letter code */
  2626.         vim_setenv("LANG", buf);
  2627.     }
  2628.     }
  2629. # endif
  2630.  
  2631.     /* enc_default() will try setting p_enc to a value depending on the
  2632.      * current locale */
  2633.     if (enc_default() == OK)
  2634.     {
  2635.     opt_idx = findoption((char_u *)"encoding");
  2636.     options[opt_idx].def_val[VI_DEFAULT] = p_enc;
  2637.     options[opt_idx].flags |= P_DEF_ALLOCED;
  2638.     }
  2639. #endif
  2640. }
  2641.  
  2642. /*
  2643.  * Set an option to its default value.
  2644.  * This does not take care of side effects!
  2645.  */
  2646.     static void
  2647. set_option_default(opt_idx, opt_flags, compatible)
  2648.     int        opt_idx;
  2649.     int        opt_flags;    /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
  2650.     int        compatible;    /* use Vi default value */
  2651. {
  2652.     char_u    *varp;        /* pointer to variable for current option */
  2653.     int        dvi;        /* index in def_val[] */
  2654.     long_u    flags;
  2655.     int        both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
  2656.  
  2657.     varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
  2658.     flags = options[opt_idx].flags;
  2659.     if (varp != NULL)        /* nothing to do for hidden option */
  2660.     {
  2661.     dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
  2662.     if (flags & P_STRING)
  2663.     {
  2664.         /* Use set_string_option_direct() for local options to handle
  2665.          * freeing and allocating the value. */
  2666.         if (options[opt_idx].indir != PV_NONE)
  2667.         set_string_option_direct(NULL, opt_idx,
  2668.                     options[opt_idx].def_val[dvi], opt_flags);
  2669.         else
  2670.         {
  2671.         if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
  2672.             free_string_option(*(char_u **)(varp));
  2673.         *(char_u **)varp = options[opt_idx].def_val[dvi];
  2674.         options[opt_idx].flags &= ~P_ALLOCED;
  2675.         }
  2676.     }
  2677.     else if (flags & P_NUM)
  2678.     {
  2679.         if (varp == (char_u *)PV_SCROLL)
  2680.         win_comp_scroll(curwin);
  2681.         else
  2682.         {
  2683.         *(long *)varp = (long)options[opt_idx].def_val[dvi];
  2684.         /* May also set global value for local option. */
  2685.         if (both)
  2686.             *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
  2687.                                 *(long *)varp;
  2688.         }
  2689.     }
  2690.     else    /* P_BOOL */
  2691.     {
  2692.         /* the cast to long is required for Manx C */
  2693.         *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
  2694.         /* May also set global value for local option. */
  2695.         if (both)
  2696.         *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
  2697.                                 *(int *)varp;
  2698.     }
  2699.     }
  2700. }
  2701.  
  2702. /*
  2703.  * Set all options (except terminal options) to their default value.
  2704.  */
  2705.     static void
  2706. set_options_default(opt_flags)
  2707.     int        opt_flags;    /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
  2708. {
  2709.     int        i;
  2710. #ifdef FEAT_WINDOWS
  2711.     win_T    *wp;
  2712. #endif
  2713.  
  2714.     for (i = 0; !istermoption(&options[i]); i++)
  2715.     if (!(options[i].flags & P_NODEFAULT))
  2716.         set_option_default(i, opt_flags, p_cp);
  2717.  
  2718. #ifdef FEAT_WINDOWS
  2719.     /* The 'scroll' option must be computed for all windows. */
  2720.     for (wp = firstwin; wp != NULL; wp = wp->w_next)
  2721.     win_comp_scroll(wp);
  2722. #else
  2723.     win_comp_scroll(curwin);
  2724. #endif
  2725. }
  2726.  
  2727. /*
  2728.  * Set the Vi-default value of a string option.
  2729.  * Used for 'sh', 'backupskip' and 'term'.
  2730.  */
  2731.     void
  2732. set_string_default(name, val)
  2733.     char    *name;
  2734.     char_u    *val;
  2735. {
  2736.     char_u    *p;
  2737.     int        opt_idx;
  2738.  
  2739.     p = vim_strsave(val);
  2740.     if (p != NULL)        /* we don't want a NULL */
  2741.     {
  2742.     opt_idx = findoption((char_u *)name);
  2743.     if (options[opt_idx].flags & P_DEF_ALLOCED)
  2744.         vim_free(options[opt_idx].def_val[VI_DEFAULT]);
  2745.     options[opt_idx].def_val[VI_DEFAULT] = p;
  2746.     options[opt_idx].flags |= P_DEF_ALLOCED;
  2747.     }
  2748. }
  2749.  
  2750. /*
  2751.  * Set the Vi-default value of a number option.
  2752.  * Used for 'lines' and 'columns'.
  2753.  */
  2754.     void
  2755. set_number_default(name, val)
  2756.     char    *name;
  2757.     long    val;
  2758. {
  2759.     options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
  2760. }
  2761.  
  2762. /*
  2763.  * Initialize the options, part two: After getting Rows and Columns and
  2764.  * setting 'term'.
  2765.  */
  2766.     void
  2767. set_init_2()
  2768. {
  2769.     /*
  2770.      * 'scroll' defaults to half the window height. Note that this default is
  2771.      * wrong when the window height changes.
  2772.      */
  2773.     options[findoption((char_u *)"scroll")].def_val[VI_DEFAULT]
  2774.                           = (char_u *)((long_u)Rows >> 1);
  2775.     comp_col();
  2776.  
  2777. #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
  2778.     {
  2779.     int    idx4;
  2780.  
  2781.     /*
  2782.      * If 'background' wasn't set by the user, try guessing the value,
  2783.      * depending on the terminal name.  Only need to check for terminals
  2784.      * with a dark background, that can handle color.  Only "linux"
  2785.      * console at the moment.
  2786.      */
  2787.     idx4 = findoption((char_u *)"bg");
  2788.     if (!(options[idx4].flags & P_WAS_SET) && STRCMP(T_NAME, "linux") == 0)
  2789.         set_string_option_direct(NULL, idx4, (char_u *)"dark", OPT_FREE);
  2790.     }
  2791. #endif
  2792. }
  2793.  
  2794. /*
  2795.  * Initialize the options, part three: After reading the .vimrc
  2796.  */
  2797.     void
  2798. set_init_3()
  2799. {
  2800. #if defined(UNIX) || defined(OS2) || defined(WIN3264)
  2801. /*
  2802.  * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
  2803.  * This is done after other initializations, where 'shell' might have been
  2804.  * set, but only if they have not been set before.
  2805.  */
  2806.     char_u  *p;
  2807.     int        idx_srr;
  2808.     int        do_srr;
  2809. #ifdef FEAT_QUICKFIX
  2810.     int        idx_sp;
  2811.     int        do_sp;
  2812. #endif
  2813.  
  2814.     idx_srr = findoption((char_u *)"srr");
  2815.     do_srr = !(options[idx_srr].flags & P_WAS_SET);
  2816. #ifdef FEAT_QUICKFIX
  2817.     idx_sp = findoption((char_u *)"sp");
  2818.     do_sp = !(options[idx_sp].flags & P_WAS_SET);
  2819. #endif
  2820.  
  2821.     /*
  2822.      * Isolate the name of the shell:
  2823.      * - Skip beyond any path.  E.g., "/usr/bin/csh -f" -> "csh -f".
  2824.      * - Remove any argument.  E.g., "csh -f" -> "csh".
  2825.      */
  2826.     p = gettail(p_sh);
  2827.     p = vim_strnsave(p, (int)(skiptowhite(p) - p));
  2828.     if (p != NULL)
  2829.     {
  2830.     /*
  2831.      * Default for p_sp is "| tee", for p_srr is ">".
  2832.      * For known shells it is changed here to include stderr.
  2833.      */
  2834.     if (       fnamecmp(p, "csh") == 0
  2835.         || fnamecmp(p, "tcsh") == 0
  2836. # if defined(OS2) || defined(WIN3264)    /* also check with .exe extension */
  2837.         || fnamecmp(p, "csh.exe") == 0
  2838.         || fnamecmp(p, "tcsh.exe") == 0
  2839. # endif
  2840.        )
  2841.     {
  2842. #if defined(FEAT_QUICKFIX) && !defined(WIN3264)
  2843.         if (do_sp)
  2844.         {
  2845.         p_sp = (char_u *)"|& tee";
  2846.         options[idx_sp].def_val[VI_DEFAULT] = p_sp;
  2847.         }
  2848. #endif
  2849.         if (do_srr)
  2850.         {
  2851.         p_srr = (char_u *)">&";
  2852.         options[idx_srr].def_val[VI_DEFAULT] = p_srr;
  2853.         }
  2854.     }
  2855.     else
  2856. # ifndef OS2    /* Always use bourne shell style redirection if we reach this */
  2857.         if (       fnamecmp(p, "sh") == 0
  2858.             || fnamecmp(p, "ksh") == 0
  2859.             || fnamecmp(p, "zsh") == 0
  2860.             || fnamecmp(p, "bash") == 0
  2861. #  ifdef WIN3264
  2862.             || fnamecmp(p, "cmd") == 0
  2863.             || fnamecmp(p, "sh.exe") == 0
  2864.             || fnamecmp(p, "ksh.exe") == 0
  2865.             || fnamecmp(p, "zsh.exe") == 0
  2866.             || fnamecmp(p, "bash.exe") == 0
  2867.             || fnamecmp(p, "cmd.exe") == 0
  2868. #  endif
  2869.             )
  2870. # endif
  2871.         {
  2872. #if defined(FEAT_QUICKFIX) && !defined(WIN3264)
  2873.         if (do_sp)
  2874.         {
  2875.             p_sp = (char_u *)"2>&1| tee";
  2876.             options[idx_sp].def_val[VI_DEFAULT] = p_sp;
  2877.         }
  2878. #endif
  2879.         if (do_srr)
  2880.         {
  2881.             p_srr = (char_u *)">%s 2>&1";
  2882.             options[idx_srr].def_val[VI_DEFAULT] = p_srr;
  2883.         }
  2884.         }
  2885.     vim_free(p);
  2886.     }
  2887. #endif
  2888.  
  2889. #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
  2890.     /*
  2891.      * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
  2892.      * This is done after other initializations, where 'shell' might have been
  2893.      * set, but only if they have not been set before.  Default for p_shcf is
  2894.      * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
  2895.      * "-c" and "\"", but not for DJGPP, because it starts the shell without
  2896.      * command.com.  And for Win32 we need to set p_sxq instead.
  2897.      */
  2898.     if (strstr((char *)p_sh, "sh") != NULL)
  2899.     {
  2900.     int    idx3;
  2901.  
  2902.     idx3 = findoption((char_u *)"shcf");
  2903.     if (!(options[idx3].flags & P_WAS_SET))
  2904.     {
  2905.         p_shcf = (char_u *)"-c";
  2906.         options[idx3].def_val[VI_DEFAULT] = p_shcf;
  2907.     }
  2908.  
  2909. # ifndef DJGPP
  2910. #  ifdef WIN3264
  2911.     /* Somehow Win32 requires the quotes around the redirection too */
  2912.     idx3 = findoption((char_u *)"sxq");
  2913.     if (!(options[idx3].flags & P_WAS_SET))
  2914.     {
  2915.         p_sxq = (char_u *)"\"";
  2916.         options[idx3].def_val[VI_DEFAULT] = p_sxq;
  2917.     }
  2918. #  else
  2919.     idx3 = findoption((char_u *)"shq");
  2920.     if (!(options[idx3].flags & P_WAS_SET))
  2921.     {
  2922.         p_shq = (char_u *)"\"";
  2923.         options[idx3].def_val[VI_DEFAULT] = p_shq;
  2924.     }
  2925. #  endif
  2926. # endif
  2927.     }
  2928. #endif
  2929.  
  2930. #ifdef FEAT_TITLE
  2931.     set_title_defaults();
  2932. #endif
  2933. }
  2934.  
  2935. #ifdef FEAT_GUI
  2936. /*
  2937.  * Option initializations that can only be done after opening the GUI window.
  2938.  */
  2939.     void
  2940. init_gui_options()
  2941. {
  2942.     /* Set the 'background' option according to the lightness of the
  2943.      * background color. */
  2944.     if (!option_was_set((char_u *)"bg")
  2945.                    && gui_get_lightness(gui.back_pixel) < 127)
  2946.     {
  2947.     set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
  2948.     highlight_changed();
  2949.     }
  2950. }
  2951. #endif
  2952.  
  2953. #ifdef FEAT_TITLE
  2954. /*
  2955.  * 'title' and 'icon' only default to true if they have not been set or reset
  2956.  * in .vimrc and we can read the old value.
  2957.  * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
  2958.  * they can be reset.  This reduces startup time when using X on a remote
  2959.  * machine.
  2960.  */
  2961.     void
  2962. set_title_defaults()
  2963. {
  2964.     int        idx1;
  2965.     long    val;
  2966.  
  2967.     /*
  2968.      * If GUI is (going to be) used, we can always set the window title and
  2969.      * icon name.  Saves a bit of time, because the X11 display server does
  2970.      * not need to be contacted.
  2971.      */
  2972.     idx1 = findoption((char_u *)"title");
  2973.     if (!(options[idx1].flags & P_WAS_SET))
  2974.     {
  2975. #ifdef FEAT_GUI
  2976.     if (gui.starting || gui.in_use)
  2977.         val = TRUE;
  2978.     else
  2979. #endif
  2980.         val = mch_can_restore_title();
  2981.     options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
  2982.     p_title = val;
  2983.     }
  2984.     idx1 = findoption((char_u *)"icon");
  2985.     if (!(options[idx1].flags & P_WAS_SET))
  2986.     {
  2987. #ifdef FEAT_GUI
  2988.     if (gui.starting || gui.in_use)
  2989.         val = TRUE;
  2990.     else
  2991. #endif
  2992.         val = mch_can_restore_icon();
  2993.     options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
  2994.     p_icon = val;
  2995.     }
  2996. }
  2997. #endif
  2998.  
  2999. /*
  3000.  * Parse 'arg' for option settings.
  3001.  *
  3002.  * 'arg' may be IObuff, but only when no errors can be present and option
  3003.  * does not need to be expanded with option_expand().
  3004.  * "opt_flags":
  3005.  * 0 for ":set"
  3006.  * OPT_GLOBAL for ":setglobal"
  3007.  * OPT_LOCAL for ":setlocal" and a modeline
  3008.  * OPT_MODELINE for a modeline
  3009.  *
  3010.  * returns FAIL if an error is detected, OK otherwise
  3011.  */
  3012.     int
  3013. do_set(arg, opt_flags)
  3014.     char_u    *arg;        /* option string (may be written to!) */
  3015.     int        opt_flags;
  3016. {
  3017.     int        opt_idx;
  3018.     char_u    *errmsg;
  3019.     char_u    errbuf[80];
  3020.     char_u    *startarg;
  3021.     int        prefix;    /* 1: nothing, 0: "no", 2: "inv" in front of name */
  3022.     int        nextchar;        /* next non-white char after option name */
  3023.     int        afterchar;        /* character just after option name */
  3024.     int        len;
  3025.     int        i;
  3026.     long    value;
  3027.     int        key;
  3028.     long_u    flags;            /* flags for current option */
  3029.     char_u    *varp = NULL;        /* pointer to variable for current option */
  3030.     int        did_show = FALSE;   /* already showed one value */
  3031.     int        adding;            /* "opt+=arg" */
  3032.     int        prepending;        /* "opt^=arg" */
  3033.     int        removing;        /* "opt-=arg" */
  3034.     int        cp_val = 0;
  3035.     char_u    key_name[2];
  3036.  
  3037.     if (*arg == NUL)
  3038.     {
  3039.     showoptions(0, opt_flags);
  3040.     return OK;
  3041.     }
  3042.  
  3043.     while (*arg != NUL)        /* loop to process all options */
  3044.     {
  3045.     errmsg = NULL;
  3046.     startarg = arg;        /* remember for error message */
  3047.  
  3048.     if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]))
  3049.     {
  3050.         /*
  3051.          * ":set all"  show all options.
  3052.          * ":set all&" set all options to their default value.
  3053.          */
  3054.         arg += 3;
  3055.         if (*arg == '&')
  3056.         {
  3057.         ++arg;
  3058.         /* Only for :set command set global value of local options. */
  3059.         set_options_default(OPT_FREE | opt_flags);
  3060.         }
  3061.         else
  3062.         showoptions(1, opt_flags);
  3063.     }
  3064.     else if (STRNCMP(arg, "termcap", 7) == 0)
  3065.     {
  3066.         showoptions(2, opt_flags);
  3067.         show_termcodes();
  3068.         arg += 7;
  3069.     }
  3070.     else
  3071.     {
  3072.         prefix = 1;
  3073.         if (STRNCMP(arg, "no", 2) == 0)
  3074.         {
  3075.         prefix = 0;
  3076.         arg += 2;
  3077.         }
  3078.         else if (STRNCMP(arg, "inv", 3) == 0)
  3079.         {
  3080.         prefix = 2;
  3081.         arg += 3;
  3082.         }
  3083.  
  3084.         /* find end of name */
  3085.         key = 0;
  3086.         if (*arg == '<')
  3087.         {
  3088.         nextchar = 0;
  3089.         opt_idx = -1;
  3090.         /* look out for <t_>;> */
  3091.         if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
  3092.             len = 5;
  3093.         else
  3094.         {
  3095.             len = 1;
  3096.             while (arg[len] != NUL && arg[len] != '>')
  3097.             ++len;
  3098.         }
  3099.         if (arg[len] != '>')
  3100.         {
  3101.             errmsg = e_invarg;
  3102.             goto skip;
  3103.         }
  3104.         arg[len] = NUL;                /* put NUL after name */
  3105.         if (arg[1] == 't' && arg[2] == '_') /* could be term code */
  3106.             opt_idx = findoption(arg + 1);
  3107.         arg[len++] = '>';            /* restore '>' */
  3108.         if (opt_idx == -1)
  3109.             key = find_key_option(arg + 1);
  3110.         }
  3111.         else
  3112.         {
  3113.         len = 0;
  3114.         /*
  3115.          * The two characters after "t_" may not be alphanumeric.
  3116.          */
  3117.         if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
  3118.             len = 4;
  3119.         else
  3120.             while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
  3121.             ++len;
  3122.         nextchar = arg[len];
  3123.         arg[len] = NUL;                /* put NUL after name */
  3124.         opt_idx = findoption(arg);
  3125.         arg[len] = nextchar;            /* restore nextchar */
  3126.         if (opt_idx == -1)
  3127.             key = find_key_option(arg);
  3128.         }
  3129.  
  3130.         /* remember character after option name */
  3131.         afterchar = arg[len];
  3132.  
  3133.         /* skip white space, allow ":set ai  ?" */
  3134.         while (vim_iswhite(arg[len]))
  3135.         ++len;
  3136.  
  3137.         adding = FALSE;
  3138.         prepending = FALSE;
  3139.         removing = FALSE;
  3140.         if (arg[len] != NUL && arg[len + 1] == '=')
  3141.         {
  3142.         if (arg[len] == '+')
  3143.         {
  3144.             adding = TRUE;        /* "+=" */
  3145.             ++len;
  3146.         }
  3147.         else if (arg[len] == '^')
  3148.         {
  3149.             prepending = TRUE;        /* "^=" */
  3150.             ++len;
  3151.         }
  3152.         else if (arg[len] == '-')
  3153.         {
  3154.             removing = TRUE;        /* "-=" */
  3155.             ++len;
  3156.         }
  3157.         }
  3158.         nextchar = arg[len];
  3159.  
  3160.         if (opt_idx == -1 && key == 0)    /* found a mismatch: skip */
  3161.         {
  3162.         errmsg = (char_u *)N_("Unknown option");
  3163.         goto skip;
  3164.         }
  3165.  
  3166.         if (opt_idx >= 0)
  3167.         {
  3168.         if (options[opt_idx].var == NULL)   /* hidden option: skip */
  3169.         {
  3170.             /* Only give an error message when requesting the value of
  3171.              * a hidden option, ignore setting it. */
  3172.             if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
  3173.                 && (!(options[opt_idx].flags & P_BOOL)
  3174.                 || nextchar == '?'))
  3175.             errmsg = (char_u *)N_("Option not supported");
  3176.             goto skip;
  3177.         }
  3178.  
  3179.         flags = options[opt_idx].flags;
  3180.         varp = get_varp_scope(&(options[opt_idx]), opt_flags);
  3181.         }
  3182.         else
  3183.         {
  3184.         flags = P_STRING;
  3185.         if (key < 0)
  3186.         {
  3187.             key_name[0] = KEY2TERMCAP0(key);
  3188.             key_name[1] = KEY2TERMCAP1(key);
  3189.         }
  3190.         else
  3191.         {
  3192.             key_name[0] = KS_KEY;
  3193.             key_name[1] = (key & 0xff);
  3194.         }
  3195.         }
  3196.  
  3197.         /* Disallow changing some options from modelines */
  3198.         if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
  3199.         {
  3200.         errmsg = (char_u *)_("Not allowed in a modeline");
  3201.         goto skip;
  3202.         }
  3203.  
  3204.         if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
  3205.         {
  3206.         arg += len;
  3207.         cp_val = p_cp;
  3208.         if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
  3209.         {
  3210.             if (arg[3] == 'm')    /* "opt&vim": set to Vim default */
  3211.             {
  3212.             cp_val = FALSE;
  3213.             arg += 3;
  3214.             }
  3215.             else        /* "opt&vi": set to Vi default */
  3216.             {
  3217.             cp_val = TRUE;
  3218.             arg += 2;
  3219.             }
  3220.         }
  3221.         if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
  3222.             && arg[1] != NUL && !vim_iswhite(arg[1]))
  3223.         {
  3224.             errmsg = e_trailing;
  3225.             goto skip;
  3226.         }
  3227.         }
  3228.  
  3229.         /*
  3230.          * allow '=' and ':' as MSDOS command.com allows only one
  3231.          * '=' character per "set" command line. grrr. (jw)
  3232.          */
  3233.         if (nextchar == '?'
  3234.             || (prefix == 1
  3235.             && vim_strchr((char_u *)"=:&<", nextchar) == NULL
  3236.             && !(flags & P_BOOL)))
  3237.         {
  3238.         /*
  3239.          * print value
  3240.          */
  3241.         if (did_show)
  3242.             msg_putchar('\n');        /* cursor below last one */
  3243.         else
  3244.         {
  3245.             gotocmdline(TRUE);        /* cursor at status line */
  3246.             did_show = TRUE;        /* remember that we did a line */
  3247.         }
  3248.         if (opt_idx >= 0)
  3249.         {
  3250.             showoneopt(&options[opt_idx], opt_flags);
  3251. #ifdef FEAT_EVAL
  3252.             if (p_verbose > 0)
  3253.             {
  3254.             if (options[opt_idx].scriptID != 0)
  3255.             {
  3256.                 MSG_PUTS(_("\n\tLast set from "));
  3257.                 MSG_PUTS(get_scriptname(options[opt_idx].scriptID));
  3258.             }
  3259.             }
  3260. #endif
  3261.         }
  3262.         else
  3263.         {
  3264.             char_u        *p;
  3265.  
  3266.             p = find_termcode(key_name);
  3267.             if (p == NULL)
  3268.             {
  3269.             errmsg = (char_u *)N_("Unknown option");
  3270.             goto skip;
  3271.             }
  3272.             else
  3273.             (void)show_one_termcode(key_name, p, TRUE);
  3274.         }
  3275.         if (nextchar != '?'
  3276.             && nextchar != NUL && !vim_iswhite(afterchar))
  3277.             errmsg = e_trailing;
  3278.         }
  3279.         else
  3280.         {
  3281.         if (flags & P_BOOL)            /* boolean */
  3282.         {
  3283.             if (nextchar == '=' || nextchar == ':')
  3284.             {
  3285.             errmsg = e_invarg;
  3286.             goto skip;
  3287.             }
  3288.  
  3289.             /*
  3290.              * ":set opt!": invert
  3291.              * ":set opt&": reset to default value
  3292.              * ":set opt<": reset to global value
  3293.              */
  3294.             if (nextchar == '!')
  3295.             value = *(int *)(varp) ^ 1;
  3296.             else if (nextchar == '&')
  3297.             value = (int)(long)options[opt_idx].def_val[
  3298.                         ((flags & P_VI_DEF) || cp_val)
  3299.                          ?  VI_DEFAULT : VIM_DEFAULT];
  3300.             else if (nextchar == '<')
  3301.             {
  3302.             /* For 'autoread' -1 means to use global value. */
  3303.             if ((int *)varp == &curbuf->b_p_ar
  3304.                             && opt_flags == OPT_LOCAL)
  3305.                 value = -1;
  3306.             else
  3307.                 value = *(int *)get_varp_scope(&(options[opt_idx]),
  3308.                                   OPT_GLOBAL);
  3309.             }
  3310.             else
  3311.             {
  3312.             /*
  3313.              * ":set invopt": invert
  3314.              * ":set opt" or ":set noopt": set or reset
  3315.              */
  3316.             if (nextchar != NUL && !vim_iswhite(afterchar))
  3317.             {
  3318.                 errmsg = e_trailing;
  3319.                 goto skip;
  3320.             }
  3321.             if (prefix == 2)    /* inv */
  3322.                 value = *(int *)(varp) ^ 1;
  3323.             else
  3324.                 value = prefix;
  3325.             }
  3326.  
  3327.             errmsg = set_bool_option(opt_idx, varp, (int)value,
  3328.                                    opt_flags);
  3329.         }
  3330.         else                    /* numeric or string */
  3331.         {
  3332.             if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
  3333.                                    || prefix != 1)
  3334.             {
  3335.             errmsg = e_invarg;
  3336.             goto skip;
  3337.             }
  3338.  
  3339.             if (flags & P_NUM)            /* numeric */
  3340.             {
  3341.             /*
  3342.              * Different ways to set a number option:
  3343.              * &        set to default value
  3344.              * <        set to global value
  3345.              * <xx>        accept special key codes for 'wildchar'
  3346.              * c        accept any non-digit for 'wildchar'
  3347.              * [-]0-9   set number
  3348.              * other    error
  3349.              */
  3350.             ++arg;
  3351.             if (nextchar == '&')
  3352.                 value = (long)options[opt_idx].def_val[
  3353.                         ((flags & P_VI_DEF) || cp_val)
  3354.                          ?  VI_DEFAULT : VIM_DEFAULT];
  3355.             else if (nextchar == '^')
  3356.                 value = *(long *)get_varp_scope(&(options[opt_idx]),
  3357.                                   OPT_GLOBAL);
  3358.             else if (((long *)varp == &p_wc
  3359.                     || (long *)varp == &p_wcm)
  3360.                 && (*arg == '<'
  3361.                     || *arg == '^'
  3362.                     || ((!arg[1] || vim_iswhite(arg[1]))
  3363.                     && !isdigit(*arg))))
  3364.             {
  3365.                 value = string_to_key(arg);
  3366.                 if (value == 0 && (long *)varp != &p_wcm)
  3367.                 {
  3368.                 errmsg = e_invarg;
  3369.                 goto skip;
  3370.                 }
  3371.             }
  3372.                 /* allow negative numbers (for 'undolevels') */
  3373.             else if (*arg == '-' || isdigit(*arg))
  3374.             {
  3375.                 i = 0;
  3376.                 if (*arg == '-')
  3377.                 i = 1;
  3378. #ifdef HAVE_STRTOL
  3379.                 value = strtol((char *)arg, NULL, 0);
  3380.                 if (arg[i] == '0' && TO_LOWER(arg[i + 1]) == 'x')
  3381.                 i += 2;
  3382. #else
  3383.                 value = atol((char *)arg);
  3384. #endif
  3385.                 while (isdigit(arg[i]))
  3386.                 ++i;
  3387.                 if (arg[i] != NUL && !vim_iswhite(arg[i]))
  3388.                 {
  3389.                 errmsg = e_invarg;
  3390.                 goto skip;
  3391.                 }
  3392.             }
  3393.             else
  3394.             {
  3395.                 errmsg = (char_u *)N_("Number required after =");
  3396.                 goto skip;
  3397.             }
  3398.  
  3399.             if (adding)
  3400.                 value = *(long *)varp + value;
  3401.             if (prepending)
  3402.                 value = *(long *)varp * value;
  3403.             if (removing)
  3404.                 value = *(long *)varp - value;
  3405.             errmsg = set_num_option(opt_idx, varp, value,
  3406.                                errbuf, opt_flags);
  3407.             }
  3408.             else if (opt_idx >= 0)            /* string */
  3409.             {
  3410.             char_u        *save_arg = NULL;
  3411.             char_u        *s = NULL;
  3412.             char_u        *oldval;    /* previous value if *varp */
  3413.             char_u        *newval;
  3414.             char_u        *origval;
  3415.             unsigned    newlen;
  3416.             int        comma;
  3417.             int        bs;
  3418.             int        new_value_alloced;    /* new string option
  3419.                                was allocated */
  3420.  
  3421.             /* When using ":set opt=val" for a global option
  3422.              * with a local value the local value will be
  3423.              * reset, use the global value here. */
  3424.             if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
  3425.                 && (int)options[opt_idx].indir >= PV_BOTH)
  3426.                 varp = options[opt_idx].var;
  3427.  
  3428.             /* The old value is kept until we are sure that the
  3429.              * new value is valid. */
  3430.             oldval = *(char_u **)varp;
  3431.             if (nextchar == '&')    /* set to default val */
  3432.             {
  3433.                 newval = options[opt_idx].def_val[
  3434.                         ((flags & P_VI_DEF) || cp_val)
  3435.                          ?  VI_DEFAULT : VIM_DEFAULT];
  3436.                 if ((char_u **)varp == &p_bg)
  3437.                 {
  3438. #ifdef FEAT_GUI
  3439.                 if (gui.in_use)
  3440.                 {
  3441.                     /* guess the value of 'background' */
  3442.                     if (gui_get_lightness(gui.back_pixel) < 127)
  3443.                     newval = (char_u *)"dark";
  3444.                     else
  3445.                     newval = (char_u *)"light";
  3446.                 }
  3447.                 else
  3448. #endif
  3449.                     if (STRCMP(T_NAME, "linux") == 0)
  3450.                     newval = (char_u *)"dark";
  3451.                 }
  3452.  
  3453.                 /* expand environment variables and ~ (since the
  3454.                  * default value was already expanded, only
  3455.                  * required when an environment variable was set
  3456.                  * later */
  3457.                 if (newval == NULL)
  3458.                 newval = empty_option;
  3459.                 else
  3460.                 {
  3461.                 s = option_expand(opt_idx, newval);
  3462.                 if (s == NULL)
  3463.                     s = vim_strsave(newval);
  3464.                 newval = s;
  3465.                 }
  3466.                 new_value_alloced = TRUE;
  3467.             }
  3468.             else if (nextchar == '<')    /* set to global val */
  3469.             {
  3470.                 newval = *(char_u **)get_varp_scope(
  3471.                          &(options[opt_idx]), OPT_GLOBAL);
  3472.                 new_value_alloced = FALSE;
  3473.             }
  3474.             else
  3475.             {
  3476.                 ++arg;    /* jump to after the '=' or ':' */
  3477.  
  3478.                 /*
  3479.                  * Convert 'whichwrap' number to string, for
  3480.                  * backwards compatibility with Vim 3.0.
  3481.                  * Misuse errbuf[] for the resulting string.
  3482.                  */
  3483.                 if (varp == (char_u *)&p_ww && isdigit(*arg))
  3484.                 {
  3485.                 *errbuf = NUL;
  3486.                 i = getdigits(&arg);
  3487.                 if (i & 1)
  3488.                     STRCAT(errbuf, "b,");
  3489.                 if (i & 2)
  3490.                     STRCAT(errbuf, "s,");
  3491.                 if (i & 4)
  3492.                     STRCAT(errbuf, "h,l,");
  3493.                 if (i & 8)
  3494.                     STRCAT(errbuf, "<,>,");
  3495.                 if (i & 16)
  3496.                     STRCAT(errbuf, "[,],");
  3497.                 if (*errbuf != NUL)    /* remove trailing , */
  3498.                     errbuf[STRLEN(errbuf) - 1] = NUL;
  3499.                 save_arg = arg;
  3500.                 arg = errbuf;
  3501.                 }
  3502.                 /*
  3503.                  * Remove '>' before 'dir' and 'bdir', for
  3504.                  * backwards compatibility with version 3.0
  3505.                  */
  3506.                 else if (  *arg == '>'
  3507.                     && (varp == (char_u *)&p_dir
  3508.                         || varp == (char_u *)&p_bdir))
  3509.                 {
  3510.                 ++arg;
  3511.                 }
  3512.  
  3513.                 /* When setting the local value of a global
  3514.                  * option, the old value may be the global value. */
  3515.                 if ((int)options[opt_idx].indir >= PV_BOTH
  3516.                            && (opt_flags & OPT_LOCAL))
  3517.                 origval = *(char_u **)get_varp(
  3518.                                &options[opt_idx]);
  3519.                 else
  3520.                 origval = oldval;
  3521.  
  3522.                 /*
  3523.                  * Copy the new string into allocated memory.
  3524.                  * Can't use set_string_option_direct(), because
  3525.                  * we need to remove the backslashes.
  3526.                  */
  3527.                 /* get a bit too much */
  3528.                 newlen = (unsigned)STRLEN(arg) + 1;
  3529.                 if (adding || prepending || removing)
  3530.                 newlen += (unsigned)STRLEN(origval) + 1;
  3531.                 newval = alloc(newlen);
  3532.                 if (newval == NULL)  /* out of mem, don't change */
  3533.                 break;
  3534.                 s = newval;
  3535.  
  3536.                 /*
  3537.                  * Copy the string, skip over escaped chars.
  3538.                  * For MS-DOS and WIN32 backslashes before normal
  3539.                  * file name characters are not removed, and keep
  3540.                  * backslash at start, for "\\machine\path", but
  3541.                  * do remove it for "\\\\machine\\path".
  3542.                  */
  3543.                 while (*arg && !vim_iswhite(*arg))
  3544.                 {
  3545.                 if (*arg == '\\' && arg[1] != NUL
  3546. #ifdef BACKSLASH_IN_FILENAME
  3547.                     && !((flags & P_EXPAND)
  3548.                         && vim_isfilec(arg[1])
  3549.                         && (arg[1] != '\\'
  3550.                             || (s == newval
  3551.                             && arg[2] != '\\')))
  3552. #endif
  3553.                                     )
  3554.                     ++arg;
  3555.                 *s++ = *arg++;
  3556.                 }
  3557.                 *s = NUL;
  3558.  
  3559.                 /*
  3560.                  * Expand environment variables and ~.
  3561.                  * Don't do it when adding without inserting a
  3562.                  * comma.
  3563.                  */
  3564.                 if (!(adding || prepending || removing)
  3565.                              || (flags & P_COMMA))
  3566.                 {
  3567.                 s = option_expand(opt_idx, newval);
  3568.                 if (s != NULL)
  3569.                 {
  3570.                     vim_free(newval);
  3571.                     newlen = (unsigned)STRLEN(s) + 1;
  3572.                     if (adding || prepending || removing)
  3573.                     newlen += (unsigned)STRLEN(origval) + 1;
  3574.                     newval = alloc(newlen);
  3575.                     if (newval == NULL)
  3576.                     break;
  3577.                     STRCPY(newval, s);
  3578.                 }
  3579.                 }
  3580.  
  3581.                 /* locate newval[] in origval[] when removing it
  3582.                  * and when adding to avoid duplicates */
  3583.                 i = 0;    /* init for GCC */
  3584.                 if (removing || (flags & P_NODUP))
  3585.                 {
  3586.                 i = (int)STRLEN(newval);
  3587.                 bs = 0;
  3588.                 for (s = origval; *s; ++s)
  3589.                 {
  3590.                     if ((!(flags & P_COMMA)
  3591.                         || s == origval
  3592.                         || (s[-1] == ',' && !(bs & 1)))
  3593.                         && STRNCMP(s, newval, i) == 0
  3594.                         && (!(flags & P_COMMA)
  3595.                         || s[i] == ','
  3596.                         || s[i] == NUL))
  3597.                     break;
  3598.                     /* Count backspaces.  Only a comma with an
  3599.                      * even number of backspaces before it is
  3600.                      * recognized as a separator */
  3601.                     if (s > origval && s[-1] == '\\')
  3602.                     ++bs;
  3603.                     else
  3604.                     bs = 0;
  3605.                 }
  3606.  
  3607.                 /* do not add if already there */
  3608.                 if ((adding || prepending) && *s)
  3609.                 {
  3610.                     prepending = FALSE;
  3611.                     adding = FALSE;
  3612.                     STRCPY(newval, origval);
  3613.                 }
  3614.                 }
  3615.  
  3616.                 /* concatenate the two strings; add a ',' if
  3617.                  * needed */
  3618.                 if (adding || prepending)
  3619.                 {
  3620.                 comma = ((flags & P_COMMA) && *origval);
  3621.                 if (adding)
  3622.                 {
  3623.                     i = (int)STRLEN(origval);
  3624.                     mch_memmove(newval + i + comma, newval,
  3625.                               STRLEN(newval) + 1);
  3626.                     mch_memmove(newval, origval, (size_t)i);
  3627.                 }
  3628.                 else
  3629.                 {
  3630.                     i = (int)STRLEN(newval);
  3631.                     mch_memmove(newval + i + comma, origval,
  3632.                               STRLEN(origval) + 1);
  3633.                 }
  3634.                 if (comma)
  3635.                     newval[i] = ',';
  3636.                 }
  3637.  
  3638.                 /* Remove newval[] from origval[]. (Note: "i" has
  3639.                  * been set above and is used here). */
  3640.                 if (removing)
  3641.                 {
  3642.                 STRCPY(newval, origval);
  3643.                 if (*s)
  3644.                 {
  3645.                     /* may need to remove a comma */
  3646.                     if (flags & P_COMMA)
  3647.                     {
  3648.                     if (s == origval)
  3649.                     {
  3650.                         /* include comma after string */
  3651.                         if (s[i] == ',')
  3652.                         ++i;
  3653.                     }
  3654.                     else
  3655.                     {
  3656.                         /* include comma before string */
  3657.                         --s;
  3658.                         ++i;
  3659.                     }
  3660.                     }
  3661.                     mch_memmove(newval + (s - origval), s + i,
  3662.                                STRLEN(s + i) + 1);
  3663.                 }
  3664.                 }
  3665.  
  3666.                 if (flags & P_FLAGLIST)
  3667.                 {
  3668.                 /* Remove flags that appear twice. */
  3669.                 for (s = newval; *s; ++s)
  3670.                     if ((!(flags & P_COMMA) || *s != ',')
  3671.                         && vim_strchr(s + 1, *s) != NULL)
  3672.                     {
  3673.                     STRCPY(s, s + 1);
  3674.                     --s;
  3675.                     }
  3676.                 }
  3677.  
  3678.                 if (save_arg != NULL)   /* number for 'whichwrap' */
  3679.                 arg = save_arg;
  3680.                 new_value_alloced = TRUE;
  3681.             }
  3682.  
  3683.             /* Set the new value. */
  3684.             *(char_u **)(varp) = newval;
  3685.  
  3686.             /* Handle side effects, and set the global value for
  3687.              * ":set" on local options. */
  3688.             errmsg = did_set_string_option(opt_idx, (char_u **)varp,
  3689.                 new_value_alloced, oldval, errbuf, opt_flags);
  3690.  
  3691.             /* If error detected, print the error message. */
  3692.             if (errmsg != NULL)
  3693.                 goto skip;
  3694.             }
  3695.             else        /* key code option */
  3696.             {
  3697.             char_u        *p;
  3698.  
  3699.             if (nextchar == '&')
  3700.             {
  3701.                 if (add_termcap_entry(key_name, TRUE) == FAIL)
  3702.                 errmsg = (char_u *)N_("Not found in termcap");
  3703.             }
  3704.             else
  3705.             {
  3706.                 ++arg; /* jump to after the '=' or ':' */
  3707.                 for (p = arg; *p && !vim_iswhite(*p); ++p)
  3708.                 if (*p == '\\' && p[1] != NUL)
  3709.                     ++p;
  3710.                 nextchar = *p;
  3711.                 *p = NUL;
  3712.                 add_termcode(key_name, arg, FALSE);
  3713.                 *p = nextchar;
  3714.             }
  3715.             if (full_screen)
  3716.                 ttest(FALSE);
  3717.             redraw_all_later(CLEAR);
  3718.             }
  3719.         }
  3720.         if (opt_idx >= 0)
  3721.             options[opt_idx].flags |= P_WAS_SET;
  3722.         }
  3723.  
  3724. skip:
  3725.         /*
  3726.          * Advance to next argument.
  3727.          * - skip until a blank found, taking care of backslashes
  3728.          * - skip blanks
  3729.          * - skip one "=val" argument (for hidden options ":set gfn =xx")
  3730.          */
  3731.         for (i = 0; i < 2 ; ++i)
  3732.         {
  3733.         while (*arg != NUL && !vim_iswhite(*arg))
  3734.             if (*arg++ == '\\' && *arg != NUL)
  3735.             ++arg;
  3736.         arg = skipwhite(arg);
  3737.         if (*arg != '=')
  3738.             break;
  3739.         }
  3740.     }
  3741.     arg = skipwhite(arg);
  3742.  
  3743.     if (errmsg != NULL)
  3744.     {
  3745.         ++no_wait_return;    /* wait_return done below */
  3746.         EMSG(_(errmsg));    /* show error highlighted */
  3747.         MSG_PUTS(": ");
  3748.                 /* show argument normal */
  3749.         while (startarg < arg)
  3750.         startarg = msg_outtrans_one(startarg, 0);
  3751.         msg_end();        /* check for scrolling */
  3752.         --no_wait_return;
  3753.  
  3754.         return FAIL;
  3755.     }
  3756.     }
  3757.  
  3758.     return OK;
  3759. }
  3760.  
  3761.     static char_u *
  3762. illegal_char(errbuf, c)
  3763.     char_u    *errbuf;
  3764.     int        c;
  3765. {
  3766.     if (errbuf == NULL)
  3767.     return (char_u *)"";
  3768.     sprintf((char *)errbuf, _("Illegal character <%s>"), (char *)transchar(c));
  3769.     return errbuf;
  3770. }
  3771.  
  3772. /*
  3773.  * Convert a key name or string into a key value.
  3774.  * Used for 'wildchar' and 'cedit' options.
  3775.  */
  3776.     static int
  3777. string_to_key(arg)
  3778.     char_u    *arg;
  3779. {
  3780.     if (*arg == '<')
  3781.     return find_key_option(arg + 1);
  3782.     if (*arg == '^')
  3783.     return Ctrl_chr(arg[1]);
  3784.     return *arg;
  3785. }
  3786.  
  3787. #ifdef FEAT_CMDWIN
  3788. /*
  3789.  * Check value of 'cedit' and set cedit_key.
  3790.  * Returns NULL if value is OK, error message otherwise.
  3791.  */
  3792.     static char_u *
  3793. check_cedit()
  3794. {
  3795.     int n;
  3796.  
  3797.     if (*p_cedit == NUL)
  3798.     cedit_key = -1;
  3799.     else
  3800.     {
  3801.     n = string_to_key(p_cedit);
  3802.     if (vim_isprintc(n))
  3803.         return e_invarg;
  3804.     cedit_key = n;
  3805.     }
  3806.     return NULL;
  3807. }
  3808. #endif
  3809.  
  3810. #ifdef FEAT_TITLE
  3811. /*
  3812.  * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
  3813.  * maketitle() to create and display it.
  3814.  * When switching the title or icon off, call mch_restore_title() to get
  3815.  * the old value back.
  3816.  */
  3817.     static void
  3818. did_set_title(icon)
  3819.     int        icon;        /* Did set icon instead of title */
  3820. {
  3821.     if (starting != NO_SCREEN
  3822. #ifdef FEAT_GUI
  3823.         && !gui.starting
  3824. #endif
  3825.                 )
  3826.     {
  3827.     maketitle();
  3828.     if (icon)
  3829.     {
  3830.         if (!p_icon)
  3831.         mch_restore_title(2);
  3832.     }
  3833.     else
  3834.     {
  3835.         if (!p_title)
  3836.         mch_restore_title(1);
  3837.     }
  3838.     }
  3839. }
  3840. #endif
  3841.  
  3842. /*
  3843.  * set_options_bin -  called when 'bin' changes value.
  3844.  */
  3845.     void
  3846. set_options_bin(oldval, newval, opt_flags)
  3847.     int        oldval;
  3848.     int        newval;
  3849.     int        opt_flags;    /* OPT_LOCAL and/or OPT_GLOBAL */
  3850. {
  3851.     /*
  3852.      * The option values that are changed when 'bin' changes are
  3853.      * copied when 'bin is set and restored when 'bin' is reset.
  3854.      */
  3855.     if (newval)
  3856.     {
  3857.     if (!oldval)        /* switched on */
  3858.     {
  3859.         if (!(opt_flags & OPT_GLOBAL))
  3860.         {
  3861.         curbuf->b_p_tw_nobin = curbuf->b_p_tw;
  3862.         curbuf->b_p_wm_nobin = curbuf->b_p_wm;
  3863.         curbuf->b_p_ml_nobin = curbuf->b_p_ml;
  3864.         curbuf->b_p_et_nobin = curbuf->b_p_et;
  3865.         }
  3866.         if (!(opt_flags & OPT_LOCAL))
  3867.         {
  3868.         p_tw_nobin = p_tw;
  3869.         p_wm_nobin = p_wm;
  3870.         p_ml_nobin = p_ml;
  3871.         p_et_nobin = p_et;
  3872.         }
  3873.     }
  3874.  
  3875.     if (!(opt_flags & OPT_GLOBAL))
  3876.     {
  3877.         curbuf->b_p_tw = 0;    /* no automatic line wrap */
  3878.         curbuf->b_p_wm = 0;    /* no automatic line wrap */
  3879.         curbuf->b_p_ml = 0;    /* no modelines */
  3880.         curbuf->b_p_et = 0;    /* no expandtab */
  3881.     }
  3882.     if (!(opt_flags & OPT_LOCAL))
  3883.     {
  3884.         p_tw = 0;
  3885.         p_wm = 0;
  3886.         p_ml = 0;
  3887.         p_et = 0;
  3888.     }
  3889.     }
  3890.     else if (oldval)        /* switched off */
  3891.     {
  3892.     if (!(opt_flags & OPT_GLOBAL))
  3893.     {
  3894.         curbuf->b_p_tw = curbuf->b_p_tw_nobin;
  3895.         curbuf->b_p_wm = curbuf->b_p_wm_nobin;
  3896.         curbuf->b_p_ml = curbuf->b_p_ml_nobin;
  3897.         curbuf->b_p_et = curbuf->b_p_et_nobin;
  3898.     }
  3899.     if (!(opt_flags & OPT_LOCAL))
  3900.     {
  3901.         p_tw = p_tw_nobin;
  3902.         p_wm = p_wm_nobin;
  3903.         p_ml = p_ml_nobin;
  3904.         p_et = p_et_nobin;
  3905.     }
  3906.     }
  3907. }
  3908.  
  3909. #ifdef FEAT_VIMINFO
  3910. /*
  3911.  * Find the parameter represented by the given character (eg ', :, ", or /),
  3912.  * and return its associated value in the 'viminfo' string.
  3913.  * Only works for number parameters, not for 'r' or 'n'.
  3914.  * If the parameter is not specified in the string, return -1.
  3915.  */
  3916.     int
  3917. get_viminfo_parameter(type)
  3918.     int        type;
  3919. {
  3920.     char_u  *p;
  3921.  
  3922.     p = find_viminfo_parameter(type);
  3923.     if (p != NULL && isdigit(*p))
  3924.     return atoi((char *)p);
  3925.     return -1;
  3926. }
  3927.  
  3928. /*
  3929.  * Find the parameter represented by the given character (eg ', :, ", or /) in
  3930.  * the 'viminfo' option and return a pointer to the string after it.
  3931.  * Return NULL if the parameter is not specified in the string.
  3932.  */
  3933.     char_u *
  3934. find_viminfo_parameter(type)
  3935.     int        type;
  3936. {
  3937.     char_u  *p;
  3938.  
  3939.     for (p = p_viminfo; *p; ++p)
  3940.     {
  3941.     if (*p == type)
  3942.         return p + 1;
  3943.     if (*p == 'n')            /* 'n' is always the last one */
  3944.         break;
  3945.     p = vim_strchr(p, ',');        /* skip until next ',' */
  3946.     if (p == NULL)            /* hit the end without finding parameter */
  3947.         break;
  3948.     }
  3949.     return NULL;
  3950. }
  3951. #endif
  3952.  
  3953. /*
  3954.  * Expand environment variables for some string options.
  3955.  * These string options cannot be indirect!
  3956.  * If "val" is NULL expand the current value of the option.
  3957.  * Return pointer to allocated memory, or NULL when not expanded.
  3958.  */
  3959.     static char_u *
  3960. option_expand(opt_idx, val)
  3961.     int        opt_idx;
  3962.     char_u    *val;
  3963. {
  3964.     /* if option doesn't need expansion nothing to do */
  3965.     if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
  3966.     return NULL;
  3967.  
  3968.     /* If val is longer than MAXPATHL no meaningful expansion can be done,
  3969.      * expand_env would truncate the string. */
  3970.     if (val != NULL && STRLEN(val) > MAXPATHL)
  3971.     return NULL;
  3972.  
  3973.     if (val == NULL)
  3974.     val = *(char_u **)options[opt_idx].var;
  3975.  
  3976.     /*
  3977.      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
  3978.      */
  3979.     expand_env(val, NameBuff, MAXPATHL);
  3980.     if (STRCMP(NameBuff, val) == 0)   /* they are the same */
  3981.     return NULL;
  3982.  
  3983.     return vim_strsave(NameBuff);
  3984. }
  3985.  
  3986. /*
  3987.  * After setting various option values: recompute variables that depend on
  3988.  * option values.
  3989.  */
  3990.     static void
  3991. didset_options()
  3992. {
  3993.     /* initialize the table for 'iskeyword' et.al. */
  3994.     (void)init_chartab();
  3995.  
  3996. #ifdef FEAT_SESSION
  3997.     (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
  3998.     (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
  3999. #endif
  4000. #ifdef FEAT_FOLDING
  4001.     (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
  4002. #endif
  4003.     (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
  4004. #ifdef FEAT_VIRTUALEDIT
  4005.     (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
  4006. #endif
  4007. #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
  4008.     (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
  4009. #endif
  4010. #ifdef FEAT_CMDWIN
  4011.     /* set cedit_key */
  4012.     (void)check_cedit();
  4013. #endif
  4014. }
  4015.  
  4016. /*
  4017.  * Check for string options that are NULL (normally only termcap options).
  4018.  */
  4019.     void
  4020. check_options()
  4021. {
  4022.     int        opt_idx;
  4023.  
  4024.     for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
  4025.     if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
  4026.         check_string_option((char_u **)get_varp(&(options[opt_idx])));
  4027. }
  4028.  
  4029. /*
  4030.  * Check string options in a buffer for NULL value.
  4031.  */
  4032.     void
  4033. check_buf_options(buf)
  4034.     buf_T    *buf;
  4035. {
  4036. #if defined(FEAT_QUICKFIX)
  4037.     check_string_option(&buf->b_p_bh);
  4038.     check_string_option(&buf->b_p_bt);
  4039. #endif
  4040. #ifdef FEAT_MBYTE
  4041.     check_string_option(&buf->b_p_fenc);
  4042. #endif
  4043.     check_string_option(&buf->b_p_ff);
  4044. #ifdef FEAT_FIND_ID
  4045.     check_string_option(&buf->b_p_def);
  4046.     check_string_option(&buf->b_p_inc);
  4047. # ifdef FEAT_EVAL
  4048.     check_string_option(&buf->b_p_inex);
  4049. # endif
  4050. #endif
  4051. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  4052.     check_string_option(&buf->b_p_inde);
  4053.     check_string_option(&buf->b_p_indk);
  4054. #endif
  4055. #ifdef FEAT_CRYPT
  4056.     check_string_option(&buf->b_p_key);
  4057. #endif
  4058.     check_string_option(&buf->b_p_mps);
  4059.     check_string_option(&buf->b_p_fo);
  4060.     check_string_option(&buf->b_p_isk);
  4061. #ifdef FEAT_COMMENTS
  4062.     check_string_option(&buf->b_p_com);
  4063. #endif
  4064. #ifdef FEAT_FOLDING
  4065.     check_string_option(&buf->b_p_cms);
  4066. #endif
  4067.     check_string_option(&buf->b_p_nf);
  4068. #ifdef FEAT_SYN_HL
  4069.     check_string_option(&buf->b_p_syn);
  4070. #endif
  4071. #ifdef FEAT_SEARCHPATH
  4072.     check_string_option(&buf->b_p_sua);
  4073. #endif
  4074. #ifdef FEAT_CINDENT
  4075.     check_string_option(&buf->b_p_cink);
  4076.     check_string_option(&buf->b_p_cino);
  4077. #endif
  4078. #ifdef FEAT_AUTOCMD
  4079.     check_string_option(&buf->b_p_ft);
  4080. #endif
  4081. #ifdef FEAT_OSFILETYPE
  4082.     check_string_option(&buf->b_p_oft);
  4083. #endif
  4084. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  4085.     check_string_option(&buf->b_p_cinw);
  4086. #endif
  4087. #ifdef FEAT_INS_EXPAND
  4088.     check_string_option(&buf->b_p_cpt);
  4089. #endif
  4090. #ifdef FEAT_KEYMAP
  4091.     check_string_option(&buf->b_p_keymap);
  4092. #endif
  4093. #ifdef FEAT_QUICKFIX
  4094.     check_string_option(&buf->b_p_gp);
  4095.     check_string_option(&buf->b_p_mp);
  4096.     check_string_option(&buf->b_p_efm);
  4097. #endif
  4098.     check_string_option(&buf->b_p_ep);
  4099.     check_string_option(&buf->b_p_path);
  4100.     check_string_option(&buf->b_p_tags);
  4101. #ifdef FEAT_INS_EXPAND
  4102.     check_string_option(&buf->b_p_dict);
  4103.     check_string_option(&buf->b_p_tsr);
  4104. #endif
  4105. }
  4106.  
  4107. /*
  4108.  * Free the string allocated for an option.
  4109.  * Checks for the string being empty_option. This may happen if we're out of
  4110.  * memory, vim_strsave() returned NULL, which was replaced by empty_option by
  4111.  * check_options().
  4112.  * Does NOT check for P_ALLOCED flag!
  4113.  */
  4114.     void
  4115. free_string_option(p)
  4116.     char_u    *p;
  4117. {
  4118.     if (p != empty_option)
  4119.     vim_free(p);
  4120. }
  4121.  
  4122.     void
  4123. clear_string_option(pp)
  4124.     char_u    **pp;
  4125. {
  4126.     if (*pp != empty_option)
  4127.     vim_free(*pp);
  4128.     *pp = empty_option;
  4129. }
  4130.  
  4131.     static void
  4132. check_string_option(pp)
  4133.     char_u    **pp;
  4134. {
  4135.     if (*pp == NULL)
  4136.     *pp = empty_option;
  4137. }
  4138.  
  4139. /*
  4140.  * Mark a terminal option as allocated, found by a pointer into term_strings[].
  4141.  */
  4142.     void
  4143. set_term_option_alloced(p)
  4144.     char_u **p;
  4145. {
  4146.     int        opt_idx;
  4147.  
  4148.     for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
  4149.     if (options[opt_idx].var == (char_u *)p)
  4150.     {
  4151.         options[opt_idx].flags |= P_ALLOCED;
  4152.         return;
  4153.     }
  4154.     return; /* cannot happen: didn't find it! */
  4155. }
  4156.  
  4157. /*
  4158.  * Set a string option to a new value (without checking the effect).
  4159.  * The string is copied into allocated memory.
  4160.  * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
  4161.  */
  4162.     void
  4163. set_string_option_direct(name, opt_idx, val, opt_flags)
  4164.     char_u    *name;
  4165.     int        opt_idx;
  4166.     char_u    *val;
  4167.     int        opt_flags;    /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
  4168. {
  4169.     char_u    *s;
  4170.     char_u    **varp;
  4171.     int        both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
  4172.  
  4173.     if (opt_idx == -1)        /* use name */
  4174.     {
  4175.     opt_idx = findoption(name);
  4176.     if (opt_idx == -1)    /* not found (should not happen) */
  4177.         return;
  4178.     }
  4179.  
  4180.     if (options[opt_idx].var == NULL)    /* can't set hidden option */
  4181.     return;
  4182.  
  4183.     s = vim_strsave(val);
  4184.     if (s != NULL)
  4185.     {
  4186.     varp = (char_u **)get_varp_scope(&(options[opt_idx]),
  4187.                            both ? OPT_LOCAL : opt_flags);
  4188.     if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
  4189.         free_string_option(*varp);
  4190.     *varp = s;
  4191.  
  4192.     /* For buffer/window local option may also set the global value. */
  4193.     if (both)
  4194.         set_string_option_global(opt_idx, varp);
  4195.  
  4196.     options[opt_idx].flags |= P_ALLOCED;
  4197.  
  4198.     /* When setting both values of a global option with a local value,
  4199.      * make the local value empty, so that the global value is used. */
  4200.     if ((int)options[opt_idx].indir >= PV_BOTH && both)
  4201.     {
  4202.         free_string_option(*varp);
  4203.         *varp = empty_option;
  4204.     }
  4205.     }
  4206. }
  4207.  
  4208. /*
  4209.  * Set global value for string option when it's a local option.
  4210.  */
  4211.     static void
  4212. set_string_option_global(opt_idx, varp)
  4213.     int        opt_idx;    /* option index */
  4214.     char_u    **varp;        /* pointer to option variable */
  4215. {
  4216.     char_u    **p, *s;
  4217.  
  4218.     /* the global value is always allocated */
  4219.     if (options[opt_idx].var == VAR_WIN)
  4220.     p = (char_u **)GLOBAL_WO(varp);
  4221.     else
  4222.     p = (char_u **)options[opt_idx].var;
  4223.     if (options[opt_idx].indir != PV_NONE
  4224.         && p != varp
  4225.         && (s = vim_strsave(*varp)) != NULL)
  4226.     {
  4227.     free_string_option(*p);
  4228.     *p = s;
  4229.     }
  4230. }
  4231.  
  4232. /*
  4233.  * Set a string option to a new value, and handle the effects.
  4234.  */
  4235.     static void
  4236. set_string_option(opt_idx, value, opt_flags)
  4237.     int        opt_idx;
  4238.     char_u    *value;
  4239.     int        opt_flags;    /* OPT_LOCAL and/or OPT_GLOBAL */
  4240. {
  4241.     char_u    *s;
  4242.     char_u    **varp;
  4243.     char_u    *oldval;
  4244.  
  4245.     if (options[opt_idx].var == NULL)    /* don't set hidden option */
  4246.     return;
  4247.  
  4248.     s = vim_strsave(value);
  4249.     if (s != NULL)
  4250.     {
  4251.     varp = (char_u **)get_varp_scope(&(options[opt_idx]),
  4252.         (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
  4253.             ? ((int)options[opt_idx].indir >= PV_BOTH
  4254.             ? OPT_GLOBAL : OPT_LOCAL)
  4255.             : opt_flags);
  4256.     oldval = *varp;
  4257.     *varp = s;
  4258.     options[opt_idx].flags |= P_WAS_SET;
  4259.     (void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
  4260.                                    opt_flags);
  4261.     }
  4262. }
  4263.  
  4264. /*
  4265.  * Handle string options that need some action to perform when changed.
  4266.  * Returns NULL for success, or an error message for an error.
  4267.  */
  4268.     static char_u *
  4269. did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
  4270.                                     opt_flags)
  4271.     int        opt_idx;        /* index in options[] table */
  4272.     char_u    **varp;            /* pointer to the option variable */
  4273.     int        new_value_alloced;    /* new value was allocated */
  4274.     char_u    *oldval;        /* previous value of the option */
  4275.     char_u    *errbuf;        /* buffer for errors, or NULL */
  4276.     int        opt_flags;        /* OPT_LOCAL and/or OPT_GLOBAL */
  4277. {
  4278.     char_u    *errmsg = NULL;
  4279.     char_u    *s, *p;
  4280.     int        did_chartab = FALSE;
  4281.     char_u    **gvarp;
  4282.  
  4283.     /* Get the global option to compare with, otherwise we would have to check
  4284.      * two values for all local options. */
  4285.     gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
  4286.  
  4287.     /* Disallow changing some options from secure mode */
  4288.     if ((secure
  4289. #ifdef HAVE_SANDBOX
  4290.         || sandbox != 0
  4291. #endif
  4292.         ) && (options[opt_idx].flags & P_SECURE))
  4293.     {
  4294.     errmsg = (char_u *)N_("Not allowed here");
  4295.     }
  4296.  
  4297.     /* 'term' */
  4298.     else if (varp == &T_NAME)
  4299.     {
  4300.     if (T_NAME[0] == NUL)
  4301.         errmsg = (char_u *)N_("Cannot set 'term' to empty string");
  4302. #ifdef FEAT_GUI
  4303.     if (gui.in_use)
  4304.         errmsg = (char_u *)N_("Cannot change term in GUI");
  4305.     else if (term_is_gui(T_NAME))
  4306.         errmsg = (char_u *)N_("Use \":gui\" to start the GUI");
  4307. #endif
  4308.     else if (set_termname(T_NAME) == FAIL)
  4309.         errmsg = (char_u *)N_("Not found in termcap");
  4310.     else
  4311.         /* Screen colors may have changed. */
  4312.         redraw_later_clear();
  4313.     }
  4314.  
  4315.     /* 'backupcopy' */
  4316.     else if (varp == &p_bkc)
  4317.     {
  4318.     if (check_opt_strings(p_bkc, p_bkc_values, FALSE) != OK)
  4319.         errmsg = e_invarg;
  4320.     }
  4321.  
  4322.     /* 'backupext' and 'patchmode' */
  4323.     else if (varp == &p_bex || varp == &p_pm)
  4324.     {
  4325.     if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
  4326.              *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
  4327.         errmsg = (char_u *)N_("'backupext' and 'patchmode' are equal");
  4328.     }
  4329.  
  4330.     /*
  4331.      * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
  4332.      * If the new option is invalid, use old value.  'lisp' option: refill
  4333.      * chartab[] for '-' char
  4334.      */
  4335.     else if (  varp == &p_isi
  4336.         || varp == &(curbuf->b_p_isk)
  4337.         || varp == &p_isp
  4338.         || varp == &p_isf)
  4339.     {
  4340.     if (init_chartab() == FAIL)
  4341.     {
  4342.         did_chartab = TRUE;        /* need to restore it below */
  4343.         errmsg = e_invarg;        /* error in value */
  4344.     }
  4345.     }
  4346.  
  4347.     /* 'helpfile' */
  4348.     else if (varp == &p_hf)
  4349.     {
  4350.     /* May compute new values for $VIM and $VIMRUNTIME */
  4351.     if (didset_vim)
  4352.     {
  4353.         vim_setenv((char_u *)"VIM", (char_u *)"");
  4354.         didset_vim = FALSE;
  4355.     }
  4356.     if (didset_vimruntime)
  4357.     {
  4358.         vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
  4359.         didset_vimruntime = FALSE;
  4360.     }
  4361.     }
  4362.  
  4363.     /* 'highlight' */
  4364.     else if (varp == &p_hl)
  4365.     {
  4366.     if (highlight_changed() == FAIL)
  4367.         errmsg = e_invarg;    /* invalid flags */
  4368.     }
  4369.  
  4370.     /* 'nrformats' */
  4371.     else if (gvarp == &p_nf)
  4372.     {
  4373.     if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
  4374.         errmsg = e_invarg;
  4375.     }
  4376.  
  4377. #ifdef FEAT_SESSION
  4378.     /* 'sessionoptions' */
  4379.     else if (varp == &p_ssop)
  4380.     {
  4381.     if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
  4382.         errmsg = e_invarg;
  4383.     if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
  4384.     {
  4385.         /* Don't allow both "sesdir" and "curdir". */
  4386.         (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
  4387.         errmsg = e_invarg;
  4388.     }
  4389.     }
  4390.     /* 'viewoptions' */
  4391.     else if (varp == &p_vop)
  4392.     {
  4393.     if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
  4394.         errmsg = e_invarg;
  4395.     }
  4396. #endif
  4397.  
  4398.     /* 'scrollopt' */
  4399. #ifdef FEAT_SCROLLBIND
  4400.     else if (varp == &p_sbo)
  4401.     {
  4402.     if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
  4403.         errmsg = e_invarg;
  4404.     }
  4405. #endif
  4406.  
  4407.     /* 'background' */
  4408.     else if (varp == &p_bg)
  4409.     {
  4410.     if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
  4411.         init_highlight(FALSE, FALSE);
  4412.     else
  4413.         errmsg = e_invarg;
  4414.     }
  4415.  
  4416.     /* 'wildmode' */
  4417.     else if (varp == &p_wim)
  4418.     {
  4419.     if (check_opt_wim() == FAIL)
  4420.         errmsg = e_invarg;
  4421.     }
  4422.  
  4423. #ifdef FEAT_WAK
  4424.     /* 'winaltkeys' */
  4425.     else if (varp == &p_wak)
  4426.     {
  4427.     if (*p_wak == NUL
  4428.         || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
  4429.         errmsg = e_invarg;
  4430. # ifdef FEAT_MENU
  4431. #  ifdef FEAT_GUI_MOTIF
  4432.     else if (gui.in_use)
  4433.         gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
  4434. #  else
  4435. #   ifdef FEAT_GUI_GTK
  4436.     else if (gui.in_use)
  4437.         gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
  4438. #   endif
  4439. #  endif
  4440. # endif
  4441.     }
  4442. #endif
  4443.  
  4444. #ifdef FEAT_AUTOCMD
  4445.     /* 'eventignore' */
  4446.     else if (varp == &p_ei)
  4447.     {
  4448.     if (check_ei() == FAIL)
  4449.         errmsg = e_invarg;
  4450.     }
  4451. #endif
  4452.  
  4453. #ifdef FEAT_MBYTE
  4454.     /* 'encoding' and 'fileencoding' */
  4455.     else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
  4456.     {
  4457.     if (varp == &curbuf->b_p_fenc && !curbuf->b_p_ma)
  4458.         errmsg = e_modifiable;
  4459.     else
  4460.     {
  4461.         /* canonize the value, so that STRCMP() can be used on it */
  4462.         p = enc_canonize(*varp);
  4463.         if (p != NULL)
  4464.         {
  4465.         vim_free(*varp);
  4466.         *varp = p;
  4467.         }
  4468.         if (varp == &p_enc)
  4469.         errmsg = mb_init();
  4470.     }
  4471.  
  4472.     if (errmsg == NULL)
  4473.     {
  4474. #ifdef FEAT_KEYMAP
  4475.         /* When 'keymap' is used and 'encoding' changes, reload the keymap
  4476.          * (with another encoding). */
  4477.         if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
  4478.         (void)keymap_init();
  4479. #endif
  4480.  
  4481.         /* When 'termencoding' is not empty and 'encoding' changes or when
  4482.          * 'termencoding' changes, need to setup for keyboard input and
  4483.          * display output conversion. */
  4484.         if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
  4485.         {
  4486.         convert_setup(&input_conv, p_tenc, p_enc);
  4487.         convert_setup(&output_conv, p_enc, p_tenc);
  4488.         }
  4489.     }
  4490.     }
  4491. #endif
  4492.  
  4493. #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
  4494.     else if (varp == &p_imak)
  4495.     {
  4496.     if (!im_xim_isvalid_imactivate())
  4497.         errmsg = e_invarg;
  4498.     }
  4499. #endif
  4500.  
  4501. #ifdef FEAT_KEYMAP
  4502.     else if (varp == &curbuf->b_p_keymap)
  4503.     {
  4504.     /* load or unload key mapping tables */
  4505.     errmsg = keymap_init();
  4506.     }
  4507. #endif
  4508.  
  4509.     /* 'fileformat' */
  4510.     else if (gvarp == &p_ff)
  4511.     {
  4512.     if (!curbuf->b_p_ma && (opt_flags & OPT_LOCAL))
  4513.         errmsg = e_modifiable;
  4514.     else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
  4515.         errmsg = e_invarg;
  4516.     else
  4517.     {
  4518.         /* may also change 'textmode' */
  4519.         if (get_fileformat(curbuf) == EOL_DOS)
  4520.         curbuf->b_p_tx = TRUE;
  4521.         else
  4522.         curbuf->b_p_tx = FALSE;
  4523.     }
  4524.     }
  4525.  
  4526.     /* 'fileformats' */
  4527.     else if (varp == &p_ffs)
  4528.     {
  4529.     if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
  4530.         errmsg = e_invarg;
  4531.     else
  4532.     {
  4533.         /* also change 'textauto' */
  4534.         if (*p_ffs == NUL)
  4535.         p_ta = FALSE;
  4536.         else
  4537.         p_ta = TRUE;
  4538.     }
  4539.     }
  4540.  
  4541. #if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
  4542.     /* 'cryptkey' */
  4543.     else if (gvarp == &p_key)
  4544.     {
  4545.     /* Make sure the ":set" command doesn't show the new value in the
  4546.      * history. */
  4547.     remove_key_from_history();
  4548.     }
  4549. #endif
  4550.  
  4551.     /* 'matchpairs' */
  4552.     else if (gvarp == &p_mps)
  4553.     {
  4554.     /* Check for "x:y,x:y" */
  4555.     for (p = *varp; *p; p += 4)
  4556.     {
  4557.         if (!p[0] || p[1] != ':' || !p[2] || (p[3] && p[3] != ','))
  4558.         {
  4559.         errmsg = e_invarg;
  4560.         break;
  4561.         }
  4562.         if (!p[3])
  4563.         break;
  4564.     }
  4565.     }
  4566.  
  4567. #ifdef FEAT_COMMENTS
  4568.     /* 'comments' */
  4569.     else if (gvarp == &p_com)
  4570.     {
  4571.     for (s = *varp; *s; )
  4572.     {
  4573.         while (*s && *s != ':')
  4574.         {
  4575.         if (vim_strchr((char_u *)COM_ALL, *s) == NULL
  4576.                          && !isdigit(*s) && *s != '-')
  4577.         {
  4578.             errmsg = illegal_char(errbuf, *s);
  4579.             break;
  4580.         }
  4581.         ++s;
  4582.         }
  4583.         if (*s++ == NUL)
  4584.         errmsg = (char_u *)N_("Missing colon");
  4585.         else if (*s == ',' || *s == NUL)
  4586.         errmsg = (char_u *)N_("Zero length string");
  4587.         if (errmsg != NULL)
  4588.         break;
  4589.         while (*s && *s != ',')
  4590.         {
  4591.         if (*s == '\\' && s[1] != NUL)
  4592.             ++s;
  4593.         ++s;
  4594.         }
  4595.         s = skip_to_option_part(s);
  4596.     }
  4597.     }
  4598. #endif
  4599.  
  4600.     /* 'listchars' */
  4601.     else if (varp == &p_lcs)
  4602.     {
  4603.     errmsg = set_chars_option(varp);
  4604.     }
  4605.  
  4606. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  4607.     /* 'fillchars' */
  4608.     else if (varp == &p_fcs)
  4609.     {
  4610.     errmsg = set_chars_option(varp);
  4611.     }
  4612. #endif
  4613.  
  4614. #ifdef FEAT_CMDWIN
  4615.     /* 'cedit' */
  4616.     else if (varp == &p_cedit)
  4617.     {
  4618.     errmsg = check_cedit();
  4619.     }
  4620. #endif
  4621.  
  4622. #ifdef FEAT_VIMINFO
  4623.     /* 'viminfo' */
  4624.     else if (varp == &p_viminfo)
  4625.     {
  4626.     for (s = p_viminfo; *s;)
  4627.     {
  4628.         /* Check it's a valid character */
  4629.         if (vim_strchr((char_u *)"!\"%'/:cfhnr", *s) == NULL)
  4630.         {
  4631.         errmsg = illegal_char(errbuf, *s);
  4632.         break;
  4633.         }
  4634.         if (*s == 'n')    /* name is always last one */
  4635.         {
  4636.         break;
  4637.         }
  4638.         else if (*s == 'r') /* skip until next ',' */
  4639.         {
  4640.         while (*++s && *s != ',')
  4641.             ;
  4642.         }
  4643.         else if (*s == '%' || *s == '!' || *s == 'h' || *s == 'c')
  4644.         ++s;        /* no extra chars */
  4645.         else        /* must have a number */
  4646.         {
  4647.         while (isdigit(*++s))
  4648.             ;
  4649.  
  4650.         if (!isdigit(*(s - 1)))
  4651.         {
  4652.             if (errbuf != NULL)
  4653.             {
  4654.             sprintf((char *)errbuf, _("Missing number after <%s>"),
  4655.                              transchar(*(s - 1)));
  4656.             errmsg = errbuf;
  4657.             }
  4658.             else
  4659.             errmsg = (char_u *)"";
  4660.             break;
  4661.         }
  4662.         }
  4663.         if (*s == ',')
  4664.         ++s;
  4665.         else if (*s)
  4666.         {
  4667.         if (errbuf != NULL)
  4668.             errmsg = (char_u *)N_("Missing comma");
  4669.         else
  4670.             errmsg = (char_u *)"";
  4671.         break;
  4672.         }
  4673.     }
  4674.     if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
  4675.         errmsg = (char_u *)N_("Must specify a ' value");
  4676.     }
  4677. #endif /* FEAT_VIMINFO */
  4678.  
  4679.     /* terminal options */
  4680.     else if (istermoption(&options[opt_idx]) && full_screen)
  4681.     {
  4682.     /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
  4683.     if (varp == &T_CCO)
  4684.     {
  4685.         t_colors = atoi((char *)T_CCO);
  4686.         if (t_colors <= 1)
  4687.         {
  4688.         if (new_value_alloced)
  4689.             vim_free(T_CCO);
  4690.         T_CCO = empty_option;
  4691.         }
  4692.         /* We now have a different color setup, initialize it again. */
  4693.         init_highlight(TRUE, FALSE);
  4694.     }
  4695.     ttest(FALSE);
  4696.     if (varp == &T_ME)
  4697.     {
  4698.         out_str(T_ME);
  4699.         redraw_later(CLEAR);
  4700. #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
  4701.         /* Since t_me has been set, this probably means that the user
  4702.          * wants to use this as default colors.  Need to reset default
  4703.          * background/foreground colors. */
  4704.         mch_set_normal_colors();
  4705. #endif
  4706.     }
  4707.     }
  4708.  
  4709. #ifdef FEAT_LINEBREAK
  4710.     /* 'showbreak' */
  4711.     else if (varp == &p_sbr)
  4712.     {
  4713.     for (s = p_sbr; *s; ++s)
  4714.         if (byte2cells(*s) != 1)
  4715.         errmsg = (char_u *)N_("contains unprintable character");
  4716.     }
  4717. #endif
  4718.  
  4719. #ifdef FEAT_GUI
  4720.     /* 'guifont' */
  4721.     else if (varp == &p_guifont)
  4722.     {
  4723.     if (gui.in_use && gui_init_font(p_guifont, FALSE) != OK
  4724. # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON)
  4725.         && *p_guifont != '*'
  4726. # endif
  4727.         )
  4728.         errmsg = (char_u *)N_("Invalid font(s)");
  4729.     }
  4730. # ifdef FEAT_XFONTSET
  4731.     else if (varp == &p_guifontset)
  4732.     {
  4733.     if (STRCMP(p_guifontset, "*") == 0)
  4734.         errmsg = (char_u *)N_("can't select fontset");
  4735.     else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
  4736.         errmsg = (char_u *)N_("Invalid fontset");
  4737.     }
  4738. # endif
  4739. # ifdef FEAT_MBYTE
  4740.     else if (varp == &p_guifontwide)
  4741.     {
  4742.     if (STRCMP(p_guifontwide, "*") == 0)
  4743.         errmsg = (char_u *)N_("can't select wide font");
  4744.     else if (gui_get_wide_font() == FAIL)
  4745.         errmsg = (char_u *)N_("Invalid wide font");
  4746.     }
  4747. # endif
  4748. #endif
  4749.  
  4750. #ifdef CURSOR_SHAPE
  4751.     /* 'guicursor' */
  4752.     else if (varp == &p_guicursor)
  4753.     errmsg = parse_shape_opt(SHAPE_CURSOR);
  4754. #endif
  4755.  
  4756. #ifdef FEAT_MOUSESHAPE
  4757.     /* 'mouseshape' */
  4758.     else if (varp == &p_mouseshape)
  4759.     {
  4760.     errmsg = parse_shape_opt(SHAPE_MOUSE);
  4761.     update_mouseshape(-1);
  4762.     }
  4763. #endif
  4764.  
  4765. #ifdef FEAT_PRINTER
  4766.     else if (varp == &p_popt)
  4767.     errmsg = parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
  4768. #endif
  4769.  
  4770. #ifdef FEAT_LANGMAP
  4771.     /* 'langmap' */
  4772.     else if (varp == &p_langmap)
  4773.     langmap_set();
  4774. #endif
  4775.  
  4776. #ifdef FEAT_LINEBREAK
  4777.     /* 'breakat' */
  4778.     else if (varp == &p_breakat)
  4779.     fill_breakat_flags();
  4780. #endif
  4781.  
  4782. #ifdef FEAT_TITLE
  4783.     /* 'titlestring' and 'iconstring' */
  4784.     else if (varp == &p_titlestring || varp == &p_iconstring)
  4785.     {
  4786. # ifdef FEAT_STL_OPT
  4787.     int    flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
  4788.  
  4789.     /* NULL => statusline syntax */
  4790.     if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
  4791.         stl_syntax |= flagval;
  4792.     else
  4793.         stl_syntax &= ~flagval;
  4794. # endif
  4795.     did_set_title(varp == &p_iconstring);
  4796.  
  4797.     }
  4798. #endif
  4799.  
  4800. #ifdef FEAT_GUI
  4801.     /* 'guioptions' */
  4802.     else if (varp == &p_go)
  4803.     gui_init_which_components(oldval);
  4804. #endif
  4805.  
  4806. #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
  4807.     /* 'ttymouse' */
  4808.     else if (varp == &p_ttym)
  4809.     {
  4810.     if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
  4811.         errmsg = e_invarg;
  4812.     else
  4813.         check_mouse_termcode();
  4814.     }
  4815. #endif
  4816.  
  4817. #ifdef FEAT_VISUAL
  4818.     /* 'selection' */
  4819.     else if (varp == &p_sel)
  4820.     {
  4821.     if (*p_sel == NUL
  4822.         || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
  4823.         errmsg = e_invarg;
  4824.     }
  4825.  
  4826.     /* 'selectmode' */
  4827.     else if (varp == &p_slm)
  4828.     {
  4829.     if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
  4830.         errmsg = e_invarg;
  4831.     }
  4832. #endif
  4833.  
  4834. #ifdef FEAT_BROWSE
  4835.     /* 'browsedir' */
  4836.     else if (varp == &p_bsdir)
  4837.     {
  4838.     if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
  4839.         && !mch_isdir(p_bsdir))
  4840.         errmsg = e_invarg;
  4841.     }
  4842. #endif
  4843.  
  4844. #ifdef FEAT_VISUAL
  4845.     /* 'keymodel' */
  4846.     else if (varp == &p_km)
  4847.     {
  4848.     if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
  4849.         errmsg = e_invarg;
  4850.     else
  4851.     {
  4852.         km_stopsel = (vim_strchr(p_km, 'o') != NULL);
  4853.         km_startsel = (vim_strchr(p_km, 'a') != NULL);
  4854.     }
  4855.     }
  4856. #endif
  4857.  
  4858.     /* 'mousemodel' */
  4859.     else if (varp == &p_mousem)
  4860.     {
  4861.     if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
  4862.         errmsg = e_invarg;
  4863. #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
  4864.     else if (*p_mousem != *oldval)
  4865.         /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
  4866.          * to create or delete the popup menus. */
  4867.         gui_motif_update_mousemodel(root_menu);
  4868. #endif
  4869.     }
  4870.  
  4871.     /* 'switchbuf' */
  4872.     else if (varp == &p_swb)
  4873.     {
  4874.     if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
  4875.         errmsg = e_invarg;
  4876.     }
  4877.  
  4878.     /* 'debug' */
  4879.     else if (varp == &p_debug)
  4880.     {
  4881.     if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
  4882.         errmsg = e_invarg;
  4883.     }
  4884.  
  4885.     /* 'display' */
  4886.     else if (varp == &p_dy)
  4887.     {
  4888.     if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
  4889.         errmsg = e_invarg;
  4890.     else
  4891.         (void)init_chartab();
  4892.  
  4893.     }
  4894.  
  4895. #ifdef FEAT_VERTSPLIT
  4896.     /* 'eadirection' */
  4897.     else if (varp == &p_ead)
  4898.     {
  4899.     if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
  4900.         errmsg = e_invarg;
  4901.     }
  4902. #endif
  4903.  
  4904. #ifdef FEAT_CLIPBOARD
  4905.     /* 'clipboard' */
  4906.     else if (varp == &p_cb)
  4907.     errmsg = check_clipboard_option();
  4908. #endif
  4909.  
  4910. #ifdef FEAT_AUTOCMD
  4911. # ifdef FEAT_SYN_HL
  4912.     /* When 'syntax' is set, load the syntax of that name */
  4913.     else if (varp == &(curbuf->b_p_syn))
  4914.     {
  4915.     apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
  4916.                          curbuf->b_fname, TRUE, curbuf);
  4917.     }
  4918. # endif
  4919.  
  4920.     /* When 'filetype' is set, trigger the FileType autocommands of that name */
  4921.     else if (varp == &(curbuf->b_p_ft))
  4922.     {
  4923.     apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
  4924.                          curbuf->b_fname, TRUE, curbuf);
  4925.     }
  4926. #endif
  4927.  
  4928. #ifdef FEAT_QUICKFIX
  4929.     /* When 'bufhidden' is set, check for valid value. */
  4930.     else if (gvarp == &p_bh)
  4931.     {
  4932.     if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
  4933.         errmsg = e_invarg;
  4934.     }
  4935.  
  4936.     /* When 'buftype' is set, check for valid value. */
  4937.     else if (gvarp == &p_bt)
  4938.     {
  4939.     if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
  4940.         errmsg = e_invarg;
  4941.     else
  4942.     {
  4943. # ifdef FEAT_WINDOWS
  4944.         if (curwin->w_status_height)
  4945.         {
  4946.         curwin->w_redr_status = TRUE;
  4947.         redraw_later(VALID);
  4948.         }
  4949. # endif
  4950.         curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
  4951.     }
  4952.     }
  4953. #endif
  4954.  
  4955. #ifdef FEAT_STL_OPT
  4956.     /* 'statusline' or 'rulerformat' */
  4957.     else if (varp == &p_stl || varp == &p_ruf)
  4958.     {
  4959.     int wid;
  4960.  
  4961.     if (varp == &p_ruf)    /* reset ru_wid first */
  4962.         ru_wid = 0;
  4963.     s = *varp;
  4964.     if (varp == &p_ruf && *s == '%')
  4965.     {
  4966.         /* set ru_wid if 'ruf' starts with "%99(" */
  4967.         if (*++s == '-')    /* ignore a '-' */
  4968.         s++;
  4969.         wid = getdigits(&s);
  4970.         if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
  4971.         ru_wid = wid;
  4972.         else
  4973.         errmsg = check_stl_option(p_ruf);
  4974.     }
  4975.     else
  4976.         errmsg = check_stl_option(s);
  4977.     if (varp == &(p_ruf) && errmsg == NULL)
  4978.         comp_col();
  4979.     }
  4980. #endif
  4981.  
  4982. #ifdef FEAT_INS_EXPAND
  4983.     /* check if it is a valid value for 'complete' -- Acevedo */
  4984.     else if (gvarp == &p_cpt)
  4985.     {
  4986.     for (s = *varp; *s;)
  4987.     {
  4988.         while(*s == ',' || *s == ' ')
  4989.         s++;
  4990.         if (!*s)
  4991.         break;
  4992.         if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
  4993.         {
  4994.         errmsg = illegal_char(errbuf, *s);
  4995.         break;
  4996.         }
  4997.         if (*++s != NUL && *s != ',' && *s != ' ')
  4998.         {
  4999.         if (s[-1] == 'k' || s[-1] == 's')
  5000.         {
  5001.             /* skip optional filename after 'k' and 's' */
  5002.             while (*s && *s != ',' && *s != ' ')
  5003.             {
  5004.             if (*s == '\\')
  5005.                 ++s;
  5006.             ++s;
  5007.             }
  5008.         }
  5009.         else
  5010.         {
  5011.             if (errbuf != NULL)
  5012.             {
  5013.             sprintf((char *)errbuf,
  5014.                      _("Illegal character after <%c>"), *--s);
  5015.             errmsg = errbuf;
  5016.             }
  5017.             else
  5018.             errmsg = (char_u *)"";
  5019.             break;
  5020.         }
  5021.         }
  5022.     }
  5023.     }
  5024. #endif /* FEAT_INS_EXPAND */
  5025.  
  5026.  
  5027. #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
  5028.     else if (varp == &p_toolbar)
  5029.     {
  5030.     if (p_toolbar && (strstr((const char *)p_toolbar, "text")
  5031.                  || strstr((const char *)p_toolbar, "icons")))
  5032.         gui_mch_show_toolbar(TRUE);
  5033.     else
  5034.         gui_mch_show_toolbar(FALSE);
  5035.     }
  5036. #endif
  5037.  
  5038.     /* 'pastetoggle': translate key codes like in a mapping */
  5039.     else if (varp == &p_pt)
  5040.     {
  5041.     if (*p_pt)
  5042.     {
  5043.         (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
  5044.         if (p != NULL)
  5045.         {
  5046.         if (new_value_alloced)
  5047.             free_string_option(p_pt);
  5048.         p_pt = p;
  5049.         new_value_alloced = TRUE;
  5050.         }
  5051.     }
  5052.     }
  5053.  
  5054.     /* 'backspace' */
  5055.     else if (varp == &p_bs)
  5056.     {
  5057.     if (isdigit(*p_bs))
  5058.     {
  5059.         if (*p_bs >'2' || p_bs[1] != NUL)
  5060.         errmsg = e_invarg;
  5061.     }
  5062.     else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
  5063.         errmsg = e_invarg;
  5064.     }
  5065.  
  5066. #ifdef FEAT_DIFF
  5067.     /* 'diffopt' */
  5068.     else if (varp == &p_dip)
  5069.     {
  5070.     if (diffopt_changed() == FAIL)
  5071.         errmsg = e_invarg;
  5072.     }
  5073. #endif
  5074.  
  5075. #ifdef FEAT_FOLDING
  5076.     /* 'foldmethod' */
  5077.     else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
  5078.     {
  5079.     if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
  5080.         || *curwin->w_p_fdm == NUL)
  5081.         errmsg = e_invarg;
  5082.     else
  5083.         foldUpdateAll(curwin);
  5084.     }
  5085. # ifdef FEAT_EVAL
  5086.     /* 'foldexpr' */
  5087.     else if (varp == &curwin->w_p_fde)
  5088.     {
  5089.     if (foldmethodIsExpr(curwin))
  5090.         foldUpdateAll(curwin);
  5091.     }
  5092. # endif
  5093.     /* 'foldmarker' */
  5094.     else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
  5095.     {
  5096.     if (vim_strchr(*varp, ',') == NULL)
  5097.         errmsg = (char_u *)N_("comma required");
  5098.     else if (foldmethodIsMarker(curwin))
  5099.         foldUpdateAll(curwin);
  5100.     }
  5101.     /* 'commentstring' */
  5102.     else if (gvarp == &p_cms)
  5103.     {
  5104.     if (**varp != NUL
  5105.         && strstr((char *)*varp, "%s") == NULL)
  5106.         errmsg = (char_u *)N_("'commentstring' must be empty or contain %s");
  5107.     }
  5108.     /* 'foldopen' */
  5109.     else if (varp == &p_fdo)
  5110.     {
  5111.     if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
  5112.         errmsg = e_invarg;
  5113.     }
  5114.     /* 'foldclose' */
  5115.     else if (varp == &p_fcl)
  5116.     {
  5117.     if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
  5118.         errmsg = e_invarg;
  5119.     }
  5120. #endif
  5121.  
  5122. #ifdef FEAT_VIRTUALEDIT
  5123.     /* 'virtualedit' */
  5124.     else if (varp == &p_ve)
  5125.     {
  5126.     if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
  5127.         errmsg = e_invarg;
  5128.     else
  5129.         /* Recompute cursor position in case the new ve setting
  5130.          * changes something. */
  5131.         coladvance(curwin->w_virtcol);
  5132.     }
  5133. #endif
  5134.  
  5135.     /* Options that are a list of flags. */
  5136.     else
  5137.     {
  5138.     p = NULL;
  5139.     if (varp == &p_ww)
  5140.         p = (char_u *)WW_ALL;
  5141.     if (varp == &p_shm)
  5142.         p = (char_u *)SHM_ALL;
  5143.     else if (varp == &(p_cpo))
  5144.         p = (char_u *)CPO_ALL;
  5145.     else if (varp == &(curbuf->b_p_fo))
  5146.         p = (char_u *)FO_ALL;
  5147.     else if (varp == &p_mouse)
  5148.     {
  5149. #ifdef FEAT_MOUSE
  5150.         p = (char_u *)MOUSE_ALL;
  5151. #else
  5152.         if (*p_mouse != NUL)
  5153.         errmsg = (char_u *)N_("No mouse support");
  5154. #endif
  5155.     }
  5156. #if defined(FEAT_GUI)
  5157.     else if (varp == &p_go)
  5158.         p = (char_u *)GO_ALL;
  5159. #endif
  5160.     if (p != NULL)
  5161.     {
  5162.         for (s = *varp; *s; ++s)
  5163.         if (vim_strchr(p, *s) == NULL)
  5164.         {
  5165.             errmsg = illegal_char(errbuf, *s);
  5166.             break;
  5167.         }
  5168.     }
  5169.     }
  5170.  
  5171.     /*
  5172.      * If error detected, restore the previous value.
  5173.      */
  5174.     if (errmsg != NULL)
  5175.     {
  5176.     if (new_value_alloced)
  5177.         free_string_option(*varp);
  5178.     *varp = oldval;
  5179.     /*
  5180.      * When resetting some values, need to act on it.
  5181.      */
  5182.     if (did_chartab)
  5183.         (void)init_chartab();
  5184.     if (varp == &p_hl)
  5185.         (void)highlight_changed();
  5186.     }
  5187.     else
  5188.     {
  5189. #ifdef FEAT_EVAL
  5190.     /* Remember where the option was set. */
  5191.     options[opt_idx].scriptID = current_SID;
  5192. #endif
  5193.     /*
  5194.      * Free string options that are in allocated memory.
  5195.      */
  5196.     if (options[opt_idx].flags & P_ALLOCED)
  5197.         free_string_option(oldval);
  5198.     if (new_value_alloced)
  5199.         options[opt_idx].flags |= P_ALLOCED;
  5200.     else
  5201.         options[opt_idx].flags &= ~P_ALLOCED;
  5202.  
  5203.     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
  5204.         && (int)options[opt_idx].indir >= PV_BOTH)
  5205.     {
  5206.         /* global option with local value set to use global value; free
  5207.          * the local value and make it empty */
  5208.         p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
  5209.         free_string_option(*(char_u **)p);
  5210.         *(char_u **)p = empty_option;
  5211.     }
  5212.  
  5213.     /* May set global value for local option. */
  5214.     else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
  5215.         set_string_option_global(opt_idx, varp);
  5216.     }
  5217.  
  5218. #ifdef FEAT_MOUSE
  5219.     if (varp == &p_mouse)
  5220.     {
  5221. # ifdef FEAT_MOUSE_TTY
  5222.     if (*p_mouse == NUL)
  5223.         mch_setmouse(FALSE);    /* switch mouse off */
  5224.     else
  5225. # endif
  5226.         setmouse();            /* in case 'mouse' changed */
  5227.     }
  5228. #endif
  5229.  
  5230.     if (curwin->w_curswant != MAXCOL)
  5231.     curwin->w_set_curswant = TRUE;  /* in case 'showbreak' changed */
  5232.     check_redraw(options[opt_idx].flags);
  5233.  
  5234.     return errmsg;
  5235. }
  5236.  
  5237. /*
  5238.  * Handle setting 'listchars' or 'fillchars'.
  5239.  * Returns error message, NULL if it's OK.
  5240.  */
  5241.     static char_u *
  5242. set_chars_option(varp)
  5243.     char_u    **varp;
  5244. {
  5245.     int        round, i, len, entries;
  5246.     char_u    *p;
  5247.     struct charstab
  5248.     {
  5249.     int    *cp;
  5250.     char    *name;
  5251.     };
  5252. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5253.     static struct charstab filltab[] =
  5254.     {
  5255.     {&fill_stl,    "stl"},
  5256.     {&fill_stlnc,    "stlnc"},
  5257.     {&fill_vert,    "vert"},
  5258.     {&fill_fold,    "fold"},
  5259.     {&fill_diff,    "diff"},
  5260.     };
  5261. #endif
  5262.     static struct charstab lcstab[] =
  5263.     {
  5264.     {&lcs_eol,    "eol"},
  5265.     {&lcs_ext,    "extends"},
  5266.     {&lcs_prec,    "precedes"},
  5267.     {&lcs_tab2,    "tab"},
  5268.     {&lcs_trail,    "trail"},
  5269.     };
  5270.     struct charstab *tab;
  5271.  
  5272. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5273.     if (varp == &p_lcs)
  5274. #endif
  5275.     {
  5276.     tab = lcstab;
  5277.     entries = sizeof(lcstab) / sizeof(struct charstab);
  5278.     }
  5279. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5280.     else
  5281.     {
  5282.     tab = filltab;
  5283.     entries = sizeof(filltab) / sizeof(struct charstab);
  5284.     }
  5285. #endif
  5286.  
  5287.     /* first round: check for valid value, second round: assign values */
  5288.     for (round = 0; round <= 1; ++round)
  5289.     {
  5290.     if (round)
  5291.     {
  5292.         /* After checking that the value is valid: set defaults: space for
  5293.          * 'fillchars', NUL for 'listchars' */
  5294.         for (i = 0; i < entries; ++i)
  5295.         *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
  5296.         if (varp == &p_lcs)
  5297.         lcs_tab1 = NUL;
  5298. #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
  5299.         else
  5300.         fill_diff = '-';
  5301. #endif
  5302.     }
  5303.     p = *varp;
  5304.     while (*p)
  5305.     {
  5306.         for (i = 0; i < entries; ++i)
  5307.         {
  5308.         len = (int)STRLEN(tab[i].name);
  5309.         if (STRNCMP(p, tab[i].name, len) == 0
  5310.             && p[len] == ':'
  5311.             && p[len + 1] != NUL)
  5312.         {
  5313.             if (tab[i].cp == &lcs_tab2)
  5314.             ++len;
  5315.             if (p[len + 1] != NUL
  5316.                 && (p[len + 2] == ',' || p[len + 2] == NUL))
  5317.             {
  5318.             if (round)
  5319.             {
  5320.                 *(tab[i].cp) = p[len + 1];
  5321.                 if (tab[i].cp == &lcs_tab2)
  5322.                 lcs_tab1 = p[len];
  5323.             }
  5324.             p += len + 2;
  5325.             break;
  5326.             }
  5327.         }
  5328.         }
  5329.  
  5330.         if (i == entries)
  5331.         return e_invarg;
  5332.         if (*p == ',')
  5333.         ++p;
  5334.     }
  5335.     }
  5336.  
  5337.     return NULL;    /* no error */
  5338. }
  5339.  
  5340. #ifdef FEAT_STL_OPT
  5341. /*
  5342.  * Check validity of options with the 'statusline' format.
  5343.  * Return error message or NULL.
  5344.  */
  5345.     char_u *
  5346. check_stl_option(s)
  5347.     char_u    *s;
  5348. {
  5349.     int        itemcnt = 0;
  5350.     int        groupdepth = 0;
  5351.     static char_u   errbuf[80];
  5352.  
  5353.     while (*s && itemcnt < STL_MAX_ITEM)
  5354.     {
  5355.     /* Check for valid keys after % sequences */
  5356.     while (*s && *s != '%')
  5357.         s++;
  5358.     if (!*s)
  5359.         break;
  5360.     s++;
  5361.     if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
  5362.     {
  5363.         s++;
  5364.         continue;
  5365.     }
  5366.     if (*s == ')')
  5367.     {
  5368.         s++;
  5369.         groupdepth--;
  5370.         continue;
  5371.     }
  5372.     if (*s == '-')
  5373.         s++;
  5374.     while (isdigit(*s))
  5375.         s++;
  5376.     if (*s == STL_HIGHLIGHT)
  5377.         continue;
  5378.     if (*s == '.')
  5379.     {
  5380.         s++;
  5381.         while (*s && isdigit(*s))
  5382.         s++;
  5383.     }
  5384.     if (*s == '(')
  5385.     {
  5386.         groupdepth++;
  5387.         continue;
  5388.     }
  5389.     if (vim_strchr(STL_ALL, *s) == NULL)
  5390.     {
  5391.         return illegal_char(errbuf, *s);
  5392.     }
  5393.     if (*s == '{')
  5394.     {
  5395.         s++;
  5396.         while (*s != '}' && *s)
  5397.         s++;
  5398.         if (*s != '}')
  5399.         return (char_u *)N_("Unclosed expression sequence");
  5400.     }
  5401.     }
  5402.     if (itemcnt >= STL_MAX_ITEM)
  5403.     return (char_u *)N_("too many items");
  5404.     if (groupdepth != 0)
  5405.     return (char_u *)N_("unbalanced groups");
  5406.     return NULL;
  5407. }
  5408. #endif
  5409.  
  5410. #ifdef FEAT_CLIPBOARD
  5411. /*
  5412.  * Extract the items in the 'clipboard' option and set global values.
  5413.  */
  5414.     static char_u *
  5415. check_clipboard_option()
  5416. {
  5417.     int        new_unnamed = FALSE;
  5418.     int        new_autoselect = FALSE;
  5419.     int        new_autoselectml = FALSE;
  5420.     regprog_T    *new_exclude_prog = NULL;
  5421.     char_u    *errmsg = NULL;
  5422.     char_u    *p;
  5423.  
  5424.     for (p = p_cb; *p != NUL; )
  5425.     {
  5426.     if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
  5427.     {
  5428.         new_unnamed = TRUE;
  5429.         p += 7;
  5430.     }
  5431.     else if (STRNCMP(p, "autoselect", 10) == 0
  5432.                     && (p[10] == ',' || p[10] == NUL))
  5433.     {
  5434.         new_autoselect = TRUE;
  5435.         p += 10;
  5436.     }
  5437.     else if (STRNCMP(p, "autoselectml", 12) == 0
  5438.                     && (p[12] == ',' || p[12] == NUL))
  5439.     {
  5440.         new_autoselectml = TRUE;
  5441.         p += 12;
  5442.     }
  5443.     else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
  5444.     {
  5445.         p += 8;
  5446.         new_exclude_prog = vim_regcomp(p, TRUE);
  5447.         if (new_exclude_prog == NULL)
  5448.         errmsg = e_invarg;
  5449.         break;
  5450.     }
  5451.     else
  5452.     {
  5453.         errmsg = e_invarg;
  5454.         break;
  5455.     }
  5456.     if (*p == ',')
  5457.         ++p;
  5458.     }
  5459.     if (errmsg == NULL)
  5460.     {
  5461.     clip_unnamed = new_unnamed;
  5462.     clip_autoselect = new_autoselect;
  5463.     clip_autoselectml = new_autoselectml;
  5464.     vim_free(clip_exclude_prog);
  5465.     clip_exclude_prog = new_exclude_prog;
  5466.     }
  5467.     else
  5468.     vim_free(new_exclude_prog);
  5469.  
  5470.     return errmsg;
  5471. }
  5472. #endif
  5473.  
  5474. /*
  5475.  * Set the value of a boolean option, and take care of side effects.
  5476.  * Returns NULL for success, or an error message for an error.
  5477.  */
  5478.     static char_u *
  5479. set_bool_option(opt_idx, varp, value, opt_flags)
  5480.     int        opt_idx;        /* index in options[] table */
  5481.     char_u    *varp;            /* pointer to the option variable */
  5482.     int        value;            /* new value */
  5483.     int        opt_flags;        /* OPT_LOCAL and/or OPT_GLOBAL */
  5484. {
  5485.     int        old_value = *(int *)varp;
  5486.  
  5487. #ifdef FEAT_GUI
  5488.     need_mouse_correct = TRUE;
  5489. #endif
  5490.  
  5491.     /* Disallow changing some options from secure mode */
  5492.     if ((secure
  5493. #ifdef HAVE_SANDBOX
  5494.         || sandbox != 0
  5495. #endif
  5496.         ) && (options[opt_idx].flags & P_SECURE))
  5497.     return (char_u *)N_("Not allowed here");
  5498.  
  5499.     *(int *)varp = value;        /* set the new value */
  5500. #ifdef FEAT_EVAL
  5501.     /* Remember where the option was set. */
  5502.     options[opt_idx].scriptID = current_SID;
  5503. #endif
  5504.  
  5505.     /* May set global value for local option. */
  5506.     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
  5507.     *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
  5508.  
  5509.     /*
  5510.      * Handle side effects of changing a bool option.
  5511.      */
  5512.  
  5513.     /* 'compatible' */
  5514.     if ((int *)varp == &p_cp)
  5515.     {
  5516.     compatible_set();
  5517.     }
  5518.  
  5519.     /* when 'readonly' is reset globally, also reset readonlymode */
  5520.     else if ((int *)varp == &curbuf->b_p_ro)
  5521.     {
  5522.     if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
  5523.         readonlymode = FALSE;
  5524. #ifdef FEAT_TITLE
  5525.     maketitle();
  5526. #endif
  5527.     }
  5528.  
  5529. #ifdef FEAT_TITLE
  5530.     /* when 'modifiable' is changed, redraw the window title */
  5531.     else if ((int *)varp == &curbuf->b_p_ma)
  5532.     maketitle();
  5533. #endif
  5534.  
  5535.     /* when 'bin' is set also set some other options */
  5536.     else if ((int *)varp == &curbuf->b_p_bin)
  5537.     {
  5538.     set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
  5539.     }
  5540.  
  5541. #ifdef FEAT_AUTOCMD
  5542.     /* when 'buflisted' changes, trigger autocommands */
  5543.     else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
  5544.     {
  5545.     apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
  5546.                             NULL, NULL, TRUE, curbuf);
  5547.     }
  5548. #endif
  5549.  
  5550.     /* when 'swf' is set, create swapfile, when reset remove swapfile */
  5551.     else if ((int *)varp == &curbuf->b_p_swf)
  5552.     {
  5553.     if (curbuf->b_p_swf && p_uc)
  5554.         ml_open_file(curbuf);        /* create the swap file */
  5555.     else
  5556.         mf_close_file(curbuf, TRUE);    /* remove the swap file */
  5557.     }
  5558.  
  5559.     /* when 'terse' is set change 'shortmess' */
  5560.     else if ((int *)varp == &p_terse)
  5561.     {
  5562.     char_u    *p;
  5563.  
  5564.     p = vim_strchr(p_shm, SHM_SEARCH);
  5565.  
  5566.     /* insert 's' in p_shm */
  5567.     if (p_terse && p == NULL)
  5568.     {
  5569.         STRCPY(IObuff, p_shm);
  5570.         STRCAT(IObuff, "s");
  5571.         set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
  5572.     }
  5573.     /* remove 's' from p_shm */
  5574.     else if (!p_terse && p != NULL)
  5575.         mch_memmove(p, p + 1, STRLEN(p));
  5576.     }
  5577.  
  5578.     /* when 'paste' is set or reset also change other options */
  5579.     else if ((int *)varp == &p_paste)
  5580.     {
  5581.     paste_option_changed();
  5582.     }
  5583.  
  5584.     /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
  5585.     else if ((int *)varp == &p_ic && p_hls)
  5586.     {
  5587.     redraw_all_later(NOT_VALID);
  5588.     }
  5589.  
  5590. #ifdef FEAT_SEARCH_EXTRA
  5591.     /* when 'hlsearch' is set or reset: reset no_hlsearch */
  5592.     else if ((int *)varp == &p_hls)
  5593.     {
  5594.     no_hlsearch = FALSE;
  5595.     }
  5596. #endif
  5597.  
  5598. #ifdef FEAT_SCROLLBIND
  5599.     /* when 'scrollbind' is set: snapshot the current position to avoid a jump
  5600.      * at the end of normal_cmd() */
  5601.     else if ((int *)varp == &curwin->w_p_scb)
  5602.     {
  5603.     if (curwin->w_p_scb)
  5604.         do_check_scrollbind(FALSE);
  5605.     }
  5606. #endif
  5607.  
  5608. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  5609.     /* There can be only one window with 'previewwindow' set. */
  5610.     else if ((int *)varp == &curwin->w_p_pvw)
  5611.     {
  5612.     if (curwin->w_p_pvw)
  5613.     {
  5614.         win_T    *win;
  5615.  
  5616.         for (win = firstwin; win != NULL; win = win->w_next)
  5617.         if (win->w_p_pvw && win != curwin)
  5618.         {
  5619.             curwin->w_p_pvw = FALSE;
  5620.             return (char_u *)N_("A preview window already exists");
  5621.         }
  5622.     }
  5623.     }
  5624. #endif
  5625.  
  5626.     /* when 'textmode' is set or reset also change 'fileformat' */
  5627.     else if ((int *)varp == &curbuf->b_p_tx)
  5628.     {
  5629.     set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
  5630.     }
  5631.  
  5632.     /* when 'textauto' is set or reset also change 'fileformats' */
  5633.     else if ((int *)varp == &p_ta)
  5634.     {
  5635.     set_string_option_direct((char_u *)"ffs", -1,
  5636.                  p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
  5637.                             OPT_FREE | opt_flags);
  5638.     }
  5639.  
  5640.     /*
  5641.      * When 'lisp' option changes include/exclude '-' in
  5642.      * keyword characters.
  5643.      */
  5644. #ifdef FEAT_LISP
  5645.     else if (varp == (char_u *)&(curbuf->b_p_lisp))
  5646.     {
  5647.     (void)buf_init_chartab(curbuf, FALSE);        /* ignore errors */
  5648.     }
  5649. #endif
  5650.  
  5651. #ifdef FEAT_TITLE
  5652.     /* when 'title' changed, may need to change the title; same for 'icon' */
  5653.     else if ((int *)varp == &p_title)
  5654.     {
  5655.     did_set_title(FALSE);
  5656.     }
  5657.  
  5658.     else if ((int *)varp == &p_icon)
  5659.     {
  5660.     did_set_title(TRUE);
  5661.     }
  5662. #endif
  5663.  
  5664.     else if ((int *)varp == &curbuf->b_changed)
  5665.     {
  5666.     if (!value)
  5667.         save_file_ff(curbuf);    /* Buffer is unchanged */
  5668. #ifdef FEAT_TITLE
  5669.     maketitle();
  5670. #endif
  5671. #ifdef FEAT_AUTOCMD
  5672.     modified_was_set = value;
  5673. #endif
  5674.     }
  5675.  
  5676. #ifdef BACKSLASH_IN_FILENAME
  5677.     else if ((int *)varp == &p_ssl)
  5678.     {
  5679.     if (p_ssl)
  5680.     {
  5681.         psepc = '/';
  5682.         psepcN = '\\';
  5683.         pseps[0] = '/';
  5684.         psepsN[0] = '\\';
  5685.     }
  5686.     else
  5687.     {
  5688.         psepc = '\\';
  5689.         psepcN = '/';
  5690.         pseps[0] = '\\';
  5691.         psepsN[0] = '/';
  5692.     }
  5693.  
  5694.     /* need to adjust the file name arguments and buffer names. */
  5695.     buflist_slash_adjust();
  5696.     alist_slash_adjust();
  5697.     }
  5698. #endif
  5699.  
  5700.     /* If 'wrap' is set, set w_leftcol to zero. */
  5701.     else if ((int *)varp == &curwin->w_p_wrap)
  5702.     {
  5703.     if (curwin->w_p_wrap)
  5704.         curwin->w_leftcol = 0;
  5705.     }
  5706.  
  5707. #ifdef FEAT_WINDOWS
  5708.     else if ((int *)varp == &p_ea)
  5709.     {
  5710.     if (p_ea && !old_value)
  5711.         win_equal(curwin, 0);
  5712.     }
  5713. #endif
  5714.  
  5715.     else if ((int *)varp == &p_wiv)
  5716.     {
  5717.     /*
  5718.      * When 'weirdinvert' changed, set/reset 't_xs'.
  5719.      * Then set 'weirdinvert' according to value of 't_xs'.
  5720.      */
  5721.     if (p_wiv && !old_value)
  5722.         T_XS = (char_u *)"y";
  5723.     else if (!p_wiv && old_value)
  5724.         T_XS = empty_option;
  5725.     p_wiv = (*T_XS != NUL);
  5726.     }
  5727.  
  5728. #ifdef FEAT_SUN_WORKSHOP
  5729.     else if ((int *)varp == &p_beval)
  5730.     {
  5731.     extern BalloonEval    *balloonEval;
  5732.  
  5733.     if (p_beval == TRUE)
  5734.         gui_mch_enable_beval_area(balloonEval);
  5735.     else
  5736.         gui_mch_disable_beval_area(balloonEval);
  5737.     }
  5738. #endif
  5739.  
  5740. #ifdef FEAT_DIFF
  5741.     /* 'diff' */
  5742.     else if ((int *)varp == &curwin->w_p_diff)
  5743.     {
  5744.     win_T    *wp;
  5745.  
  5746.     if (!curwin->w_p_diff)
  5747.     {
  5748.         /* When there is no window showing a diff for this buffer, remove
  5749.          * it from the diffs. */
  5750.         for (wp = firstwin; wp != NULL; wp = wp->w_next)
  5751.         if (wp->w_buffer == curwin->w_buffer && wp->w_p_diff)
  5752.             break;
  5753.         if (wp == NULL)
  5754.         diff_buf_delete(curwin->w_buffer);
  5755.     }
  5756.     else
  5757.         diff_buf_add(curwin->w_buffer);
  5758. #ifdef FEAT_FOLDING
  5759.     if (foldmethodIsDiff(curwin))
  5760.         foldUpdateAll(curwin);
  5761. #endif
  5762.     }
  5763. #endif
  5764.  
  5765. #ifdef USE_IM_CONTROL
  5766.     /* 'imdisable' */
  5767.     else if ((int *)varp == &p_imdisable)
  5768.     {
  5769.     /* Only de-activate it here, it will be enabled when changing mode. */
  5770.     if (p_imdisable)
  5771.         im_set_active(FALSE);
  5772.     }
  5773. #endif
  5774.  
  5775. #ifdef FEAT_FKMAP
  5776.     else if ((int *)varp == &p_altkeymap)
  5777.     {
  5778.     if (old_value != p_altkeymap)
  5779.     {
  5780.         if (!p_altkeymap)
  5781.         {
  5782.         p_hkmap = p_fkmap;
  5783.         p_fkmap = 0;
  5784.         }
  5785.         else
  5786.         {
  5787.         p_fkmap = p_hkmap;
  5788.         p_hkmap = 0;
  5789.         }
  5790.         (void)init_chartab();
  5791.     }
  5792.     }
  5793.  
  5794.     /*
  5795.      * In case some second language keymapping options have changed, check
  5796.      * and correct the setting in a consistent way.
  5797.      */
  5798.     /*
  5799.      * If hkmap set, reset Farsi keymapping.
  5800.      */
  5801.     if (p_hkmap && p_altkeymap)
  5802.     {
  5803.     p_altkeymap = 0;
  5804.     p_fkmap = 0;
  5805.     (void)init_chartab();
  5806.     }
  5807.  
  5808.     /*
  5809.      * If fkmap set, reset Hebrew keymapping.
  5810.      */
  5811.     if (p_fkmap && !p_altkeymap)
  5812.     {
  5813.     p_altkeymap = 1;
  5814.     p_hkmap = 0;
  5815.     (void)init_chartab();
  5816.     }
  5817. #endif
  5818.  
  5819.     /*
  5820.      * End of handling side effects for bool options.
  5821.      */
  5822.  
  5823.     options[opt_idx].flags |= P_WAS_SET;
  5824.  
  5825.     comp_col();                /* in case 'ruler' or 'showcmd' changed */
  5826.     if (curwin->w_curswant != MAXCOL)
  5827.     curwin->w_set_curswant = TRUE;  /* in case 'list' changed */
  5828.     check_redraw(options[opt_idx].flags);
  5829.  
  5830.     return NULL;
  5831. }
  5832.  
  5833. /*
  5834.  * Set the value of a number option, and take care of side effects.
  5835.  * Returns NULL for success, or an error message for an error.
  5836.  */
  5837.     static char_u *
  5838. set_num_option(opt_idx, varp, value, errbuf, opt_flags)
  5839.     int        opt_idx;        /* index in options[] table */
  5840.     char_u    *varp;            /* pointer to the option variable */
  5841.     long    value;            /* new value */
  5842.     char_u    *errbuf;        /* buffer for error messages */
  5843.     int        opt_flags;        /* OPT_LOCAL, OPT_GLOBAL and
  5844.                        OPT_MODELINE */
  5845. {
  5846.     char_u    *errmsg = NULL;
  5847.     long    old_value = *(long *)varp;
  5848.     long    old_Rows = Rows;    /* remember old Rows */
  5849.     long    old_Columns = Columns;    /* remember old Columns */
  5850.     long    *pp = (long *)varp;
  5851.  
  5852. #ifdef FEAT_GUI
  5853.     need_mouse_correct = TRUE;
  5854. #endif
  5855.  
  5856.     *pp = value;
  5857. #ifdef FEAT_EVAL
  5858.     /* Remember where the option was set. */
  5859.     options[opt_idx].scriptID = current_SID;
  5860. #endif
  5861.  
  5862.     if (curbuf->b_p_sw <= 0)
  5863.     {
  5864.     errmsg = e_positive;
  5865.     curbuf->b_p_sw = curbuf->b_p_ts;
  5866.     }
  5867.  
  5868.     /*
  5869.      * Number options that need some action when changed
  5870.      */
  5871. #ifdef FEAT_WINDOWS
  5872.     if (pp == &p_wh || pp == &p_hh)
  5873.     {
  5874.     if (p_wh < 1)
  5875.     {
  5876.         errmsg = e_positive;
  5877.         p_wh = 1;
  5878.     }
  5879.     if (p_wmh > p_wh)
  5880.     {
  5881.         errmsg = (char_u *)N_("'winheight' cannot be smaller than 'winminheight'");
  5882.         p_wh = p_wmh;
  5883.     }
  5884.     if (p_hh < 0)
  5885.     {
  5886.         errmsg = e_positive;
  5887.         p_hh = 0;
  5888.     }
  5889.  
  5890.     /* Change window height NOW */
  5891.     if (lastwin != firstwin)
  5892.     {
  5893.         if (pp == &p_wh && curwin->w_height < p_wh)
  5894.         win_setheight((int)p_wh);
  5895.         if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
  5896.         win_setheight((int)p_hh);
  5897.     }
  5898.     }
  5899.  
  5900.     /* 'winminheight' */
  5901.     else if (pp == &p_wmh)
  5902.     {
  5903.     if (p_wmh < 0)
  5904.     {
  5905.         errmsg = e_positive;
  5906.         p_wmh = 0;
  5907.     }
  5908.     if (p_wmh > p_wh)
  5909.     {
  5910.         errmsg = (char_u *)N_("'winheight' cannot be smaller than 'winminheight'");
  5911.         p_wmh = p_wh;
  5912.     }
  5913.     win_setminheight();
  5914.     }
  5915.  
  5916. # ifdef FEAT_VERTSPLIT
  5917.     if (pp == &p_wiw)
  5918.     {
  5919.     if (p_wiw < 1)
  5920.     {
  5921.         errmsg = e_positive;
  5922.         p_wiw = 1;
  5923.     }
  5924.     if (p_wmw > p_wiw)
  5925.     {
  5926.         errmsg = (char_u *)N_("'winwidth' cannot be smaller than 'winminwidth'");
  5927.         p_wiw = p_wmw;
  5928.     }
  5929.  
  5930.     /* Change window width NOW */
  5931.     if (lastwin != firstwin && curwin->w_width < p_wiw)
  5932.         win_setwidth((int)p_wiw);
  5933.     }
  5934.  
  5935.     /* 'winminwidth' */
  5936.     else if (pp == &p_wmw)
  5937.     {
  5938.     if (p_wmw < 0)
  5939.     {
  5940.         errmsg = e_positive;
  5941.         p_wmw = 0;
  5942.     }
  5943.     if (p_wmw > p_wiw)
  5944.     {
  5945.         errmsg = (char_u *)N_("'winwidth' cannot be smaller than 'winminwidth'");
  5946.         p_wmw = p_wiw;
  5947.     }
  5948.     win_setminheight();
  5949.     }
  5950. # endif
  5951.  
  5952. #endif
  5953.  
  5954. #ifdef FEAT_WINDOWS
  5955.     /* (re)set last window status line */
  5956.     else if (pp == &p_ls)
  5957.     {
  5958.     last_status(FALSE);
  5959.     }
  5960. #endif
  5961.  
  5962. #ifdef FEAT_GUI
  5963.     else if (pp == &p_linespace)
  5964.     {
  5965.     if (gui.in_use && gui_mch_adjust_charsize() == OK)
  5966.         gui_set_shellsize(FALSE, FALSE);
  5967.     }
  5968. #endif
  5969.  
  5970. #ifdef FEAT_FOLDING
  5971.     /* 'foldlevel' */
  5972.     else if (pp == &curwin->w_p_fdl)
  5973.     {
  5974.     if (curwin->w_p_fdl < 0)
  5975.         curwin->w_p_fdl = 0;
  5976.     newFoldLevel();
  5977.     }
  5978.  
  5979.     /* 'foldminlevel' */
  5980.     else if (pp == &curwin->w_p_fml)
  5981.     {
  5982.     foldUpdateAll(curwin);
  5983.     }
  5984.  
  5985.     /* 'foldnestmax' */
  5986.     else if (pp == &curwin->w_p_fdn)
  5987.     {
  5988.     if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
  5989.         foldUpdateAll(curwin);
  5990.     }
  5991.  
  5992.     /* 'foldcolumn' */
  5993.     else if (pp == &curwin->w_p_fdc)
  5994.     {
  5995.     if (curwin->w_p_fdc < 0)
  5996.     {
  5997.         errmsg = e_positive;
  5998.         curwin->w_p_fdc = 0;
  5999.     }
  6000.     else if (curwin->w_p_fdc > 12)
  6001.     {
  6002.         errmsg = e_invarg;
  6003.         curwin->w_p_fdc = 12;
  6004.     }
  6005.     }
  6006.  
  6007.     /* 'shiftwidth' or 'tabstop' */
  6008.     else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
  6009.     {
  6010.     if (foldmethodIsIndent(curwin))
  6011.         foldUpdateAll(curwin);
  6012.     }
  6013. #endif /* FEAT_FOLDING */
  6014.  
  6015.     else if (pp == &curbuf->b_p_iminsert)
  6016.     {
  6017.     if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
  6018.     {
  6019.         errmsg = e_invarg;
  6020.         curbuf->b_p_iminsert = B_IMODE_NONE;
  6021.     }
  6022.     p_iminsert = curbuf->b_p_iminsert;
  6023.     showmode();
  6024. #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
  6025.     /* Show/unshow value of 'keymap' in status lines. */
  6026.     status_redraw_curbuf();
  6027. #endif
  6028.     }
  6029.  
  6030.     else if (pp == &curbuf->b_p_imsearch)
  6031.     {
  6032.     if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
  6033.     {
  6034.         errmsg = e_invarg;
  6035.         curbuf->b_p_imsearch = B_IMODE_NONE;
  6036.     }
  6037.     p_imsearch = curbuf->b_p_imsearch;
  6038.     }
  6039.  
  6040. #ifdef FEAT_TITLE
  6041.     /* if 'titlelen' has changed, redraw the title */
  6042.     else if (pp == &p_titlelen)
  6043.     {
  6044.     if (p_titlelen < 0)
  6045.     {
  6046.         errmsg = e_positive;
  6047.         p_titlelen = 85;
  6048.     }
  6049.     if (starting != NO_SCREEN && old_value != p_titlelen)
  6050.         maketitle();
  6051.     }
  6052. #endif
  6053.  
  6054.     /* if p_ch changed value, change the command line height */
  6055.     else if (pp == &p_ch)
  6056.     {
  6057.     if (p_ch < 1)
  6058.     {
  6059.         errmsg = e_positive;
  6060.         p_ch = 1;
  6061.     }
  6062.     if (p_ch != old_value)
  6063.         command_height(old_value);
  6064.     }
  6065.  
  6066.     /* when 'updatecount' changes from zero to non-zero, open swap files */
  6067.     else if (pp == &p_uc)
  6068.     {
  6069.     if (p_uc < 0)
  6070.     {
  6071.         errmsg = e_positive;
  6072.         p_uc = 100;
  6073.     }
  6074.     if (p_uc && !old_value)
  6075.         ml_open_files();
  6076.     }
  6077.  
  6078.     /*
  6079.      * Check the bounds for numeric options here
  6080.      */
  6081.     if (Rows < min_rows() && full_screen)
  6082.     {
  6083.     if (errbuf != NULL)
  6084.     {
  6085.         sprintf((char *)errbuf, _("Need at least %d lines"), min_rows());
  6086.         errmsg = errbuf;
  6087.     }
  6088.     Rows = min_rows();
  6089.     }
  6090.     if (Columns < MIN_COLUMNS && full_screen)
  6091.     {
  6092.     if (errbuf != NULL)
  6093.     {
  6094.         sprintf((char *)errbuf, _("Need at least %d columns"), MIN_COLUMNS);
  6095.         errmsg = errbuf;
  6096.     }
  6097.     Columns = MIN_COLUMNS;
  6098.     }
  6099.  
  6100. #ifdef DJGPP
  6101.     /* avoid a crash by checking for a too large value of 'columns' */
  6102.     if (old_Columns != Columns && full_screen && term_console)
  6103.     mch_check_columns();
  6104. #endif
  6105.  
  6106.     /*
  6107.      * If the screen (shell) height has been changed, assume it is the
  6108.      * physical screenheight.
  6109.      */
  6110.     if (old_Rows != Rows || old_Columns != Columns)
  6111.     {
  6112.     if (full_screen
  6113. #ifdef FEAT_GUI
  6114.         && !gui.starting
  6115. #endif
  6116.         )
  6117.         set_shellsize((int)Columns, (int)Rows, TRUE);
  6118.     else
  6119.     {
  6120.         /* Postpone the resizing; check the size and cmdline position for
  6121.          * messages. */
  6122.         check_shellsize();
  6123.         if (cmdline_row > Rows - p_ch)
  6124.         cmdline_row = Rows - p_ch;
  6125.     }
  6126.     }
  6127.  
  6128.     if (curbuf->b_p_sts < 0)
  6129.     {
  6130.     errmsg = e_positive;
  6131.     curbuf->b_p_sts = 0;
  6132.     }
  6133.     if (curbuf->b_p_ts <= 0)
  6134.     {
  6135.     errmsg = e_positive;
  6136.     curbuf->b_p_ts = 8;
  6137.     }
  6138.     if (curbuf->b_p_tw < 0)
  6139.     {
  6140.     errmsg = e_positive;
  6141.     curbuf->b_p_tw = 0;
  6142.     }
  6143.     if (p_tm < 0)
  6144.     {
  6145.     errmsg = e_positive;
  6146.     p_tm = 0;
  6147.     }
  6148.     if ((curwin->w_p_scr <= 0
  6149.         || (curwin->w_p_scr > curwin->w_height
  6150.             && curwin->w_height > 0))
  6151.         && full_screen)
  6152.     {
  6153.     if (pp == &(curwin->w_p_scr))
  6154.     {
  6155.         if (curwin->w_p_scr != 0)
  6156.         errmsg = e_scroll;
  6157.         win_comp_scroll(curwin);
  6158.     }
  6159.     /* If 'scroll' became invalid because of a side effect silently adjust
  6160.      * it. */
  6161.     else if (curwin->w_p_scr <= 0)
  6162.         curwin->w_p_scr = 1;
  6163.     else /* curwin->w_p_scr > curwin->w_height */
  6164.         curwin->w_p_scr = curwin->w_height;
  6165.     }
  6166.     if (p_report < 0)
  6167.     {
  6168.     errmsg = e_positive;
  6169.     p_report = 1;
  6170.     }
  6171.     if ((p_sj < 0 || p_sj >= Rows) && full_screen)
  6172.     {
  6173.     if (Rows != old_Rows)    /* Rows changed, just adjust p_sj */
  6174.         p_sj = Rows / 2;
  6175.     else
  6176.     {
  6177.         errmsg = e_scroll;
  6178.         p_sj = 1;
  6179.     }
  6180.     }
  6181.     if (p_so < 0 && full_screen)
  6182.     {
  6183.     errmsg = e_scroll;
  6184.     p_so = 0;
  6185.     }
  6186. #ifdef FEAT_CMDWIN
  6187.     if (p_cwh < 1)
  6188.     {
  6189.     errmsg = e_positive;
  6190.     p_cwh = 1;
  6191.     }
  6192. #endif
  6193.     if (p_ut < 0)
  6194.     {
  6195.     errmsg = e_positive;
  6196.     p_ut = 2000;
  6197.     }
  6198.     if (p_ss < 0)
  6199.     {
  6200.     errmsg = e_positive;
  6201.     p_ss = 0;
  6202.     }
  6203.  
  6204.     /* May set global value for local option. */
  6205.     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
  6206.     *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
  6207.  
  6208.     options[opt_idx].flags |= P_WAS_SET;
  6209.  
  6210.     comp_col();                /* in case 'columns' or 'ls' changed */
  6211.     if (curwin->w_curswant != MAXCOL)
  6212.     curwin->w_set_curswant = TRUE;  /* in case 'tabstop' changed */
  6213.     check_redraw(options[opt_idx].flags);
  6214.  
  6215.     return errmsg;
  6216. }
  6217.  
  6218. /*
  6219.  * Called after an option changed: check if something needs to be redrawn.
  6220.  */
  6221.     static void
  6222. check_redraw(flags)
  6223.     long_u    flags;
  6224. {
  6225.     /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
  6226.     int        clear = (flags & P_RCLR) == P_RCLR;
  6227.     int        all = ((flags & P_RALL) == P_RALL || clear);
  6228.  
  6229. #ifdef FEAT_WINDOWS
  6230.     if ((flags & P_RSTAT) || all)    /* mark all status lines dirty */
  6231.     status_redraw_all();
  6232. #endif
  6233.  
  6234.     if ((flags & P_RBUF) || (flags & P_RWIN) || all)
  6235.     changed_window_setting();
  6236.     if (flags & P_RBUF)
  6237.     redraw_curbuf_later(NOT_VALID);
  6238.     if (clear)
  6239.     redraw_all_later(CLEAR);
  6240.     else if (all)
  6241.     redraw_all_later(NOT_VALID);
  6242. }
  6243.  
  6244. /*
  6245.  * Find index for option 'arg'.
  6246.  * Return -1 if not found.
  6247.  */
  6248.     static int
  6249. findoption(arg)
  6250.     char_u *arg;
  6251. {
  6252.     int            opt_idx;
  6253.     char        *s, *p;
  6254.     static short    quick_tab[27] = {0, 0};    /* quick access table */
  6255.     int            is_term_opt;
  6256.  
  6257.     /*
  6258.      * For first call: Initialize the quick-access table.
  6259.      * It contains the index for the first option that starts with a certain
  6260.      * letter.  There are 26 letters, plus the first "t_" option.
  6261.      */
  6262.     if (quick_tab[1] == 0)
  6263.     {
  6264.     p = options[0].fullname;
  6265.     for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
  6266.     {
  6267.         if (s[0] != p[0])
  6268.         {
  6269.         if (s[0] == 't' && s[1] == '_')
  6270.             quick_tab[26] = opt_idx;
  6271.         else
  6272.             quick_tab[CharOrdLow(s[0])] = opt_idx;
  6273.         }
  6274.         p = s;
  6275.     }
  6276.     }
  6277.  
  6278.     /*
  6279.      * Check for name starting with an illegal character.
  6280.      */
  6281. #ifdef EBCDIC
  6282.     if (!islower(arg[0]))
  6283. #else
  6284.     if (arg[0] < 'a' || arg[0] > 'z')
  6285. #endif
  6286.     return -1;
  6287.  
  6288.     is_term_opt = (arg[0] == 't' && arg[1] == '_');
  6289.     if (is_term_opt)
  6290.     opt_idx = quick_tab[26];
  6291.     else
  6292.     opt_idx = quick_tab[CharOrdLow(arg[0])];
  6293.     for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
  6294.     {
  6295.     if (STRCMP(arg, s) == 0)            /* match full name */
  6296.         break;
  6297.     }
  6298.     if (s == NULL && !is_term_opt)
  6299.     {
  6300.     opt_idx = quick_tab[CharOrdLow(arg[0])];
  6301.     for ( ; options[opt_idx].fullname != NULL; opt_idx++)
  6302.     {
  6303.         s = options[opt_idx].shortname;
  6304.         if (s != NULL && STRCMP(arg, s) == 0)   /* match short name */
  6305.         break;
  6306.         s = NULL;
  6307.     }
  6308.     }
  6309.     if (s == NULL)
  6310.     opt_idx = -1;
  6311.     return opt_idx;
  6312. }
  6313.  
  6314. #if defined(FEAT_EVAL) || defined(FEAT_TCL)
  6315. /*
  6316.  * Get the value for an option.
  6317.  *
  6318.  * Returns:
  6319.  * Number or Toggle option: 1, *numval gets value.
  6320.  *         String option: 0, *stringval gets allocated string.
  6321.  * Hidden Number or Toggle option: -1.
  6322.  *         hidden String option: -2.
  6323.  *           unknown option: -3.
  6324.  */
  6325.     int
  6326. get_option_value(name, numval, stringval, opt_flags)
  6327.     char_u    *name;
  6328.     long    *numval;
  6329.     char_u    **stringval;        /* NULL when only checking existance */
  6330.     int        opt_flags;
  6331. {
  6332.     int        opt_idx;
  6333.     char_u    *varp;
  6334.  
  6335.     opt_idx = findoption(name);
  6336.     if (opt_idx < 0)            /* unknown option */
  6337.     return -3;
  6338.  
  6339.     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
  6340.  
  6341.     if (options[opt_idx].flags & P_STRING)
  6342.     {
  6343.     if (varp == NULL)            /* hidden option */
  6344.         return -2;
  6345.     if (stringval != NULL)
  6346.     {
  6347. #ifdef FEAT_CRYPT
  6348.         /* never return the value of the crypt key */
  6349.         if ((char_u **)varp == &curbuf->b_p_key)
  6350.         *stringval = vim_strsave((char_u *)"*****");
  6351.         else
  6352. #endif
  6353.         *stringval = vim_strsave(*(char_u **)(varp));
  6354.     }
  6355.     return 0;
  6356.     }
  6357.  
  6358.     if (varp == NULL)            /* hidden option */
  6359.     return -1;
  6360.     if (options[opt_idx].flags & P_NUM)
  6361.     *numval = *(long *)varp;
  6362.     else
  6363.     {
  6364.     /* Special case: 'modified' is b_changed, but we also want to consider
  6365.      * it set when 'ff' or 'fenc' changed. */
  6366.     if ((int *)varp == &curbuf->b_changed)
  6367.         *numval = curbufIsChanged();
  6368.     else
  6369.         *numval = *(int *)varp;
  6370.     }
  6371.     return 1;
  6372. }
  6373. #endif
  6374.  
  6375. /*
  6376.  * Set the value of option "name".
  6377.  * Use "string" for string options, use "number" for other options.
  6378.  */
  6379.     void
  6380. set_option_value(name, number, string, opt_flags)
  6381.     char_u    *name;
  6382.     long    number;
  6383.     char_u    *string;
  6384.     int        opt_flags;    /* OPT_LOCAL or 0 (both) */
  6385. {
  6386.     int        opt_idx;
  6387.     char_u    *varp;
  6388.  
  6389.     opt_idx = findoption(name);
  6390.     if (opt_idx == -1)
  6391.     EMSG2(_("E355: Unknown option: %s"), name);
  6392.     else if (options[opt_idx].flags & P_STRING)
  6393.     set_string_option(opt_idx, string, opt_flags);
  6394.     else
  6395.     {
  6396.     varp = get_varp(&options[opt_idx]);
  6397.     if (varp != NULL)    /* hidden option is not changed */
  6398.     {
  6399.         if (options[opt_idx].flags & P_NUM)
  6400.         (void)set_num_option(opt_idx, varp, number, NULL, opt_flags);
  6401.         else
  6402.         (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
  6403.     }
  6404.     }
  6405. }
  6406.  
  6407. /*
  6408.  * Get the terminal code for a terminal option.
  6409.  * Returns NULL when not found.
  6410.  */
  6411.     char_u *
  6412. get_term_code(tname)
  6413.     char_u    *tname;
  6414. {
  6415.     int        opt_idx;
  6416.     char_u  *varp;
  6417.  
  6418.     if (tname[0] != 't' || tname[1] != '_' ||
  6419.         tname[2] == NUL || tname[3] == NUL)
  6420.     return NULL;
  6421.     if ((opt_idx = findoption(tname)) >= 0)
  6422.     {
  6423.     varp = get_varp(&(options[opt_idx]));
  6424.     if (varp != NULL)
  6425.         varp = *(char_u **)(varp);
  6426.     return varp;
  6427.     }
  6428.     return find_termcode(tname + 2);
  6429. }
  6430.  
  6431.     char_u *
  6432. get_highlight_default()
  6433. {
  6434.     int i;
  6435.  
  6436.     i = findoption((char_u *)"hl");
  6437.     if (i >= 0)
  6438.     return options[i].def_val[VI_DEFAULT];
  6439.     return (char_u *)NULL;
  6440. }
  6441.  
  6442. /*
  6443.  * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
  6444.  */
  6445.     static int
  6446. find_key_option(arg)
  6447.     char_u *arg;
  6448. {
  6449.     int        key;
  6450.     int        modifiers;
  6451.  
  6452.     /*
  6453.      * Don't use get_special_key_code() for t_xx, we don't want it to call
  6454.      * add_termcap_entry().
  6455.      */
  6456.     if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
  6457.     key = TERMCAP2KEY(arg[2], arg[3]);
  6458.     else
  6459.     {
  6460.     --arg;                /* put arg at the '<' */
  6461.     key = find_special_key(&arg, &modifiers, TRUE);
  6462.     if (modifiers)            /* can't handle modifiers here */
  6463.         key = 0;
  6464.     }
  6465.     return key;
  6466. }
  6467.  
  6468. /*
  6469.  * if 'all' == 0: show changed options
  6470.  * if 'all' == 1: show all normal options
  6471.  * if 'all' == 2: show all terminal options
  6472.  */
  6473.     static void
  6474. showoptions(all, opt_flags)
  6475.     int        all;
  6476.     int        opt_flags;    /* OPT_LOCAL and/or OPT_GLOBAL */
  6477. {
  6478.     struct vimoption    *p;
  6479.     int            col;
  6480.     int            isterm;
  6481.     char_u        *varp;
  6482.     struct vimoption    **items;
  6483.     int            item_count;
  6484.     int            run;
  6485.     int            row, rows;
  6486.     int            cols;
  6487.     int            i;
  6488.     int            len;
  6489.  
  6490. #define INC 20
  6491. #define GAP 3
  6492.  
  6493.     items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
  6494.                                 PARAM_COUNT));
  6495.     if (items == NULL)
  6496.     return;
  6497.  
  6498.     /* Highlight title */
  6499.     if (all == 2)
  6500.     MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
  6501.     else if (opt_flags & OPT_GLOBAL)
  6502.     MSG_PUTS_TITLE(_("\n--- Global option values ---"));
  6503.     else if (opt_flags & OPT_LOCAL)
  6504.     MSG_PUTS_TITLE(_("\n--- Local option values ---"));
  6505.     else
  6506.     MSG_PUTS_TITLE(_("\n--- Options ---"));
  6507.  
  6508.     /*
  6509.      * do the loop two times:
  6510.      * 1. display the short items
  6511.      * 2. display the long items (only strings and numbers)
  6512.      */
  6513.     for (run = 1; run <= 2 && !got_int; ++run)
  6514.     {
  6515.     /*
  6516.      * collect the items in items[]
  6517.      */
  6518.     item_count = 0;
  6519.     for (p = &options[0]; p->fullname != NULL; p++)
  6520.     {
  6521.         isterm = istermoption(p);
  6522.         if (!isterm && opt_flags != 0)
  6523.         {
  6524.         if (p->indir == PV_NONE)
  6525.             varp = NULL;
  6526.         else
  6527.             varp = get_varp_scope(p, opt_flags);
  6528.         }
  6529.         else
  6530.         varp = get_varp(p);
  6531.         if (varp != NULL
  6532.             && ((all == 2 && isterm)
  6533.             || (all == 1 && !isterm)
  6534.             || (all == 0 && !optval_default(p, varp))))
  6535.         {
  6536.         if (p->flags & P_BOOL)
  6537.             len = 1;        /* a toggle option fits always */
  6538.         else
  6539.         {
  6540.             option_value2string(p, opt_flags);
  6541.             len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
  6542.         }
  6543.         if ((len <= INC - GAP && run == 1) ||
  6544.                         (len > INC - GAP && run == 2))
  6545.             items[item_count++] = p;
  6546.         }
  6547.     }
  6548.  
  6549.     /*
  6550.      * display the items
  6551.      */
  6552.     if (run == 1)
  6553.     {
  6554.         cols = (Columns + GAP - 3) / INC;
  6555.         if (cols == 0)
  6556.         cols = 1;
  6557.         rows = (item_count + cols - 1) / cols;
  6558.     }
  6559.     else    /* run == 2 */
  6560.         rows = item_count;
  6561.     for (row = 0; row < rows && !got_int; ++row)
  6562.     {
  6563.         msg_putchar('\n');            /* go to next line */
  6564.         if (got_int)            /* 'q' typed in more */
  6565.         break;
  6566.         col = 0;
  6567.         for (i = row; i < item_count; i += rows)
  6568.         {
  6569.         msg_col = col;            /* make columns */
  6570.         showoneopt(items[i], opt_flags);
  6571.         col += INC;
  6572.         }
  6573.         out_flush();
  6574.         ui_breakcheck();
  6575.     }
  6576.     }
  6577.     vim_free(items);
  6578. }
  6579.  
  6580. /*
  6581.  * Return TRUE if option "p" has its default value.
  6582.  */
  6583.     static int
  6584. optval_default(p, varp)
  6585.     struct vimoption    *p;
  6586.     char_u        *varp;
  6587. {
  6588.     int        dvi;
  6589.  
  6590.     if (varp == NULL)
  6591.     return TRUE;        /* hidden option is always at default */
  6592.     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
  6593.     if (p->flags & P_NUM)
  6594.     return (*(long *)varp == (long)p->def_val[dvi]);
  6595.     if (p->flags & P_BOOL)
  6596.             /* the cast to long is required for Manx C */
  6597.     return (*(int *)varp == (int)(long)p->def_val[dvi]);
  6598.     /* P_STRING */
  6599.     return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
  6600. }
  6601.  
  6602. /*
  6603.  * showoneopt: show the value of one option
  6604.  * must not be called with a hidden option!
  6605.  */
  6606.     static void
  6607. showoneopt(p, opt_flags)
  6608.     struct vimoption    *p;
  6609.     int            opt_flags;    /* OPT_LOCAL or OPT_GLOBAL */
  6610. {
  6611.     char_u        *varp;
  6612.  
  6613.     varp = get_varp_scope(p, opt_flags);
  6614.  
  6615.     /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
  6616.     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
  6617.                     ? !curbufIsChanged() : !*(int *)varp))
  6618.     MSG_PUTS("no");
  6619.     else if ((p->flags & P_BOOL) && *(int *)varp < 0)
  6620.     MSG_PUTS("--");
  6621.     else
  6622.     MSG_PUTS("  ");
  6623.     MSG_PUTS(p->fullname);
  6624.     if (!(p->flags & P_BOOL))
  6625.     {
  6626.     msg_putchar('=');
  6627.     /* put value string in NameBuff */
  6628.     option_value2string(p, opt_flags);
  6629.     msg_outtrans(NameBuff);
  6630.     }
  6631. }
  6632.  
  6633. /*
  6634.  * Write modified options as ":set" commands to a file.
  6635.  *
  6636.  * There are three values for "opt_flags":
  6637.  * OPT_GLOBAL:           Write global option values and fresh values of
  6638.  *               buffer-local options (used for start of a session
  6639.  *               file).
  6640.  * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
  6641.  *               curwin (used for a vimrc file).
  6642.  * OPT_LOCAL:           Write buffer-local option values for curbuf, fresh
  6643.  *               and local values for window-local options of
  6644.  *               curwin.  Local values are also written when at the
  6645.  *               default value, because a modeline or autocommand
  6646.  *               may have set them when doing ":edit file" and the
  6647.  *               user has set them back at the default or fresh
  6648.  *               value.
  6649.  *               When "local_only" is TRUE, don't write fresh
  6650.  *               values, only local values (for ":mkview").
  6651.  * (fresh value = value used for a new buffer or window for a local option).
  6652.  *
  6653.  * Return FAIL on error, OK otherwise.
  6654.  */
  6655.     int
  6656. makeset(fd, opt_flags, local_only)
  6657.     FILE    *fd;
  6658.     int        opt_flags;
  6659.     int        local_only;
  6660. {
  6661.     struct vimoption    *p;
  6662.     char_u        *varp;            /* currently used value */
  6663.     char_u        *varp_fresh;        /* local value */
  6664.     char_u        *varp_local = NULL;    /* fresh value */
  6665.     char        *cmd;
  6666.     int            round;
  6667.  
  6668.     /*
  6669.      * The options that don't have a default (terminal name, columns, lines)
  6670.      * are never written.  Terminal options are also not written.
  6671.      */
  6672.     for (p = &options[0]; !istermoption(p); p++)
  6673.     if (!(p->flags & P_NO_MKRC) && !istermoption(p))
  6674.     {
  6675.         /* skip global option when only doing locals */
  6676.         if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
  6677.         continue;
  6678.  
  6679.         /* Global values are only written when not at the default value. */
  6680.         varp = get_varp_scope(p, opt_flags);
  6681.         if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
  6682.         continue;
  6683.  
  6684.         round = 2;
  6685.         if (p->indir != PV_NONE)
  6686.         {
  6687.         if (p->var == VAR_WIN)
  6688.         {
  6689.             /* skip window-local option when only doing globals */
  6690.             if (!(opt_flags & OPT_LOCAL))
  6691.             continue;
  6692.             /* When fresh value of window-local option is not at the
  6693.              * default, need to write it too. */
  6694.             if (!(opt_flags & OPT_GLOBAL) && !local_only)
  6695.             {
  6696.             varp_fresh = get_varp_scope(p, OPT_GLOBAL);
  6697.             if (!optval_default(p, varp_fresh))
  6698.             {
  6699.                 round = 1;
  6700.                 varp_local = varp;
  6701.                 varp = varp_fresh;
  6702.             }
  6703.             }
  6704.         }
  6705.         }
  6706.  
  6707.         /* Round 1: fresh value for window-local options.
  6708.          * Round 2: other values */
  6709.         for ( ; round <= 2; varp = varp_local, ++round)
  6710.         {
  6711.         if (round == 1 || (opt_flags & OPT_GLOBAL))
  6712.             cmd = "set";
  6713.         else
  6714.             cmd = "setlocal";
  6715.  
  6716.         if (p->flags & P_BOOL)
  6717.         {
  6718.             if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
  6719.             return FAIL;
  6720.         }
  6721.         else if (p->flags & P_NUM)
  6722.         {
  6723.             if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
  6724.             return FAIL;
  6725.         }
  6726.         else    /* P_STRING */
  6727.         {
  6728.             /* Don't set 'syntax' and 'filetype' again if the value is
  6729.              * already right, avoids reloading the syntax file. */
  6730.             if (p->indir == PV_SYN || p->indir == PV_FT)
  6731.             {
  6732.             if (fprintf(fd, "if &%s != '%s'", p->fullname,
  6733.                                *(char_u **)(varp)) < 0
  6734.                 || put_eol(fd) < 0)
  6735.                 return FAIL;
  6736.             }
  6737.             if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
  6738.                       (p->flags & P_EXPAND) != 0) == FAIL)
  6739.             return FAIL;
  6740.             if (p->indir == PV_SYN || p->indir == PV_FT)
  6741.             {
  6742.             if (put_line(fd, "endif") == FAIL)
  6743.                 return FAIL;
  6744.             }
  6745.         }
  6746.         }
  6747.     }
  6748.     return OK;
  6749. }
  6750.  
  6751. #if defined(FEAT_FOLDING) || defined(PROTO)
  6752. /*
  6753.  * Generate set commands for the local fold options only.  Used when
  6754.  * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
  6755.  */
  6756.     int
  6757. makefoldset(fd)
  6758.     FILE    *fd;
  6759. {
  6760.     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
  6761. # ifdef FEAT_EVAL
  6762.         || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
  6763.                                        == FAIL
  6764. # endif
  6765.         || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
  6766.                                        == FAIL
  6767.         || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
  6768.                                        == FAIL
  6769.         || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
  6770.         || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
  6771.         || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
  6772.         || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
  6773.         )
  6774.     return FAIL;
  6775.  
  6776.     return OK;
  6777. }
  6778. #endif
  6779.  
  6780.     static int
  6781. put_setstring(fd, cmd, name, valuep, expand)
  6782.     FILE    *fd;
  6783.     char    *cmd;
  6784.     char    *name;
  6785.     char_u    **valuep;
  6786.     int        expand;
  6787. {
  6788.     char_u    *s;
  6789.     char_u    buf[MAXPATHL];
  6790.  
  6791.     if (fprintf(fd, "%s %s=", cmd, name) < 0)
  6792.     return FAIL;
  6793.     if (*valuep != NULL)
  6794.     {
  6795.     /* Output 'pastetoggle' as key names.  For other
  6796.      * options some characters have to be escaped with
  6797.      * CTRL-V or backslash */
  6798.     if (valuep == &p_pt)
  6799.     {
  6800.         s = *valuep;
  6801.         while (*s != NUL)
  6802.         if (fputs((char *)str2special(&s, FALSE), fd) < 0)
  6803.             return FAIL;
  6804.     }
  6805.     else if (expand)
  6806.     {
  6807.         home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
  6808.         if (put_escstr(fd, buf, 2) == FAIL)
  6809.         return FAIL;
  6810.     }
  6811.     else if (put_escstr(fd, *valuep, 2) == FAIL)
  6812.         return FAIL;
  6813.     }
  6814.     if (put_eol(fd) < 0)
  6815.     return FAIL;
  6816.     return OK;
  6817. }
  6818.  
  6819.     static int
  6820. put_setnum(fd, cmd, name, valuep)
  6821.     FILE    *fd;
  6822.     char    *cmd;
  6823.     char    *name;
  6824.     long    *valuep;
  6825. {
  6826.     long    wc;
  6827.  
  6828.     if (fprintf(fd, "%s %s=", cmd, name) < 0)
  6829.     return FAIL;
  6830.     if (wc_use_keyname((char_u *)valuep, &wc))
  6831.     {
  6832.     /* print 'wildchar' and 'wildcharm' as a key name */
  6833.     if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
  6834.         return FAIL;
  6835.     }
  6836.     else if (fprintf(fd, "%ld", *valuep) < 0)
  6837.     return FAIL;
  6838.     if (put_eol(fd) < 0)
  6839.     return FAIL;
  6840.     return OK;
  6841. }
  6842.  
  6843.     static int
  6844. put_setbool(fd, cmd, name, value)
  6845.     FILE    *fd;
  6846.     char    *cmd;
  6847.     char    *name;
  6848.     int        value;
  6849. {
  6850.     if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
  6851.         || put_eol(fd) < 0)
  6852.     return FAIL;
  6853.     return OK;
  6854. }
  6855.  
  6856. /*
  6857.  * Clear all the terminal options.
  6858.  * If the option has been allocated, free the memory.
  6859.  * Terminal options are never hidden or indirect.
  6860.  */
  6861.     void
  6862. clear_termoptions()
  6863. {
  6864.     struct vimoption   *p;
  6865.  
  6866.     /*
  6867.      * Reset a few things before clearing the old options. This may cause
  6868.      * outputting a few things that the terminal doesn't understand, but the
  6869.      * screen will be cleared later, so this is OK.
  6870.      */
  6871. #ifdef FEAT_MOUSE_TTY
  6872.     mch_setmouse(FALSE);        /* switch mouse off */
  6873. #endif
  6874. #ifdef FEAT_TITLE
  6875.     mch_restore_title(3);        /* restore window titles */
  6876. #endif
  6877. #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
  6878.     /* When starting the GUI close the display opened for the clipboard.
  6879.      * After restoring the title, because that will need the display. */
  6880.     if (gui.starting)
  6881.     clear_xterm_clip();
  6882. #endif
  6883. #ifdef WIN3264
  6884.     /*
  6885.      * Check if this is allowed now.
  6886.      */
  6887.     if (can_end_termcap_mode(FALSE) == TRUE)
  6888. #endif
  6889.     stoptermcap();            /* stop termcap mode */
  6890.  
  6891.     for (p = &options[0]; p->fullname != NULL; p++)
  6892.     if (istermoption(p))
  6893.     {
  6894.         if (p->flags & P_ALLOCED)
  6895.         free_string_option(*(char_u **)(p->var));
  6896.         if (p->flags & P_DEF_ALLOCED)
  6897.         free_string_option(p->def_val[VI_DEFAULT]);
  6898.         *(char_u **)(p->var) = empty_option;
  6899.         p->def_val[VI_DEFAULT] = empty_option;
  6900.         p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
  6901.     }
  6902.     clear_termcodes();
  6903. }
  6904.  
  6905. /*
  6906.  * Set the terminal option defaults to the current value.
  6907.  * Used after setting the terminal name.
  6908.  */
  6909.     void
  6910. set_term_defaults()
  6911. {
  6912.     struct vimoption   *p;
  6913.  
  6914.     for (p = &options[0]; p->fullname != NULL; p++)
  6915.     {
  6916.     if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
  6917.     {
  6918.         if (p->flags & P_DEF_ALLOCED)
  6919.         {
  6920.         free_string_option(p->def_val[VI_DEFAULT]);
  6921.         p->flags &= ~P_DEF_ALLOCED;
  6922.         }
  6923.         p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
  6924.         if (p->flags & P_ALLOCED)
  6925.         {
  6926.         p->flags |= P_DEF_ALLOCED;
  6927.         p->flags &= ~P_ALLOCED;     /* don't free the value now */
  6928.         }
  6929.     }
  6930.     }
  6931. }
  6932.  
  6933. /*
  6934.  * return TRUE if 'p' starts with 't_'
  6935.  */
  6936.     static int
  6937. istermoption(p)
  6938.     struct vimoption *p;
  6939. {
  6940.     return (p->fullname[0] == 't' && p->fullname[1] == '_');
  6941. }
  6942.  
  6943. /*
  6944.  * Compute columns for ruler and shown command. 'sc_col' is also used to
  6945.  * decide what the maximum length of a message on the status line can be.
  6946.  * If there is a status line for the last window, 'sc_col' is independent
  6947.  * of 'ru_col'.
  6948.  */
  6949.  
  6950. #define COL_RULER 17        /* columns needed by standard ruler */
  6951.  
  6952.     void
  6953. comp_col()
  6954. {
  6955. #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
  6956.     int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
  6957.  
  6958.     sc_col = 0;
  6959.     ru_col = 0;
  6960.     if (p_ru)
  6961.     {
  6962. #ifdef FEAT_STL_OPT
  6963.     ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
  6964. #else
  6965.     ru_col = COL_RULER + 1;
  6966. #endif
  6967.     /* no last status line, adjust sc_col */
  6968.     if (!last_has_status)
  6969.         sc_col = ru_col;
  6970.     }
  6971.     if (p_sc)
  6972.     {
  6973.     sc_col += SHOWCMD_COLS;
  6974.     if (!p_ru || last_has_status)        /* no need for separating space */
  6975.         ++sc_col;
  6976.     }
  6977.     sc_col = Columns - sc_col;
  6978.     ru_col = Columns - ru_col;
  6979.     if (sc_col <= 0)        /* screen too narrow, will become a mess */
  6980.     sc_col = 1;
  6981.     if (ru_col <= 0)
  6982.     ru_col = 1;
  6983. #else
  6984.     sc_col = Columns;
  6985.     ru_col = Columns;
  6986. #endif
  6987. }
  6988.  
  6989. /*
  6990.  * Get pointer to option variable, depending on local or global scope.
  6991.  */
  6992.     static char_u *
  6993. get_varp_scope(p, opt_flags)
  6994.     struct vimoption    *p;
  6995.     int            opt_flags;
  6996. {
  6997.     if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
  6998.     {
  6999.     if (p->var == VAR_WIN)
  7000.         return (char_u *)GLOBAL_WO(get_varp(p));
  7001.     return p->var;
  7002.     }
  7003.     if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
  7004.     {
  7005.     switch ((int)p->indir)
  7006.     {
  7007. #ifdef FEAT_QUICKFIX
  7008.         case OPT_BOTH(PV_GP):   return (char_u *)&(curbuf->b_p_gp);
  7009.         case OPT_BOTH(PV_MP):   return (char_u *)&(curbuf->b_p_mp);
  7010.         case OPT_BOTH(PV_EFM):  return (char_u *)&(curbuf->b_p_efm);
  7011. #endif
  7012.         case OPT_BOTH(PV_EP):   return (char_u *)&(curbuf->b_p_ep);
  7013.         case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
  7014.         case OPT_BOTH(PV_AR):   return (char_u *)&(curbuf->b_p_ar);
  7015.         case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
  7016. #ifdef FEAT_FIND_ID
  7017.         case OPT_BOTH(PV_DEF):  return (char_u *)&(curbuf->b_p_def);
  7018.         case OPT_BOTH(PV_INC):  return (char_u *)&(curbuf->b_p_inc);
  7019. #endif
  7020. #ifdef FEAT_INS_EXPAND
  7021.         case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
  7022.         case OPT_BOTH(PV_TSR):  return (char_u *)&(curbuf->b_p_tsr);
  7023. #endif
  7024.     }
  7025.     return NULL; /* "cannot happen" */
  7026.     }
  7027.     return get_varp(p);
  7028. }
  7029.  
  7030. /*
  7031.  * Get pointer to option variable.
  7032.  */
  7033.     static char_u *
  7034. get_varp(p)
  7035.     struct vimoption    *p;
  7036. {
  7037.     /* hidden option, always return NULL */
  7038.     if (p->var == NULL)
  7039.     return NULL;
  7040.  
  7041.     switch ((int)p->indir)
  7042.     {
  7043.     case PV_NONE:    return p->var;
  7044.  
  7045.     /* global option with local value: use local value if it's been set */
  7046.     case OPT_BOTH(PV_EP):    return *curbuf->b_p_ep != NUL
  7047.                     ? (char_u *)&curbuf->b_p_ep : p->var;
  7048.     case OPT_BOTH(PV_PATH):    return *curbuf->b_p_path != NUL
  7049.                     ? (char_u *)&(curbuf->b_p_path) : p->var;
  7050.     case OPT_BOTH(PV_AR):    return curbuf->b_p_ar >= 0
  7051.                     ? (char_u *)&(curbuf->b_p_ar) : p->var;
  7052.     case OPT_BOTH(PV_TAGS):    return *curbuf->b_p_tags != NUL
  7053.                     ? (char_u *)&(curbuf->b_p_tags) : p->var;
  7054. #ifdef FEAT_FIND_ID
  7055.     case OPT_BOTH(PV_DEF):    return *curbuf->b_p_def != NUL
  7056.                     ? (char_u *)&(curbuf->b_p_def) : p->var;
  7057.     case OPT_BOTH(PV_INC):    return *curbuf->b_p_inc != NUL
  7058.                     ? (char_u *)&(curbuf->b_p_inc) : p->var;
  7059. #endif
  7060. #ifdef FEAT_INS_EXPAND
  7061.     case OPT_BOTH(PV_DICT):    return *curbuf->b_p_dict != NUL
  7062.                     ? (char_u *)&(curbuf->b_p_dict) : p->var;
  7063.     case OPT_BOTH(PV_TSR):    return *curbuf->b_p_tsr != NUL
  7064.                     ? (char_u *)&(curbuf->b_p_tsr) : p->var;
  7065. #endif
  7066. #ifdef FEAT_QUICKFIX
  7067.     case OPT_BOTH(PV_GP):    return *curbuf->b_p_gp != NUL
  7068.                     ? (char_u *)&(curbuf->b_p_gp) : p->var;
  7069.     case OPT_BOTH(PV_MP):    return *curbuf->b_p_mp != NUL
  7070.                     ? (char_u *)&(curbuf->b_p_mp) : p->var;
  7071.     case OPT_BOTH(PV_EFM):    return *curbuf->b_p_efm != NUL
  7072.                     ? (char_u *)&(curbuf->b_p_efm) : p->var;
  7073. #endif
  7074.  
  7075.     case PV_LIST:    return (char_u *)&(curwin->w_p_list);
  7076. #ifdef FEAT_DIFF
  7077.     case PV_DIFF:    return (char_u *)&(curwin->w_p_diff);
  7078. #endif
  7079. #ifdef FEAT_FOLDING
  7080.     case PV_FDC:    return (char_u *)&(curwin->w_p_fdc);
  7081.     case PV_FEN:    return (char_u *)&(curwin->w_p_fen);
  7082.     case PV_FDI:    return (char_u *)&(curwin->w_p_fdi);
  7083.     case PV_FDL:    return (char_u *)&(curwin->w_p_fdl);
  7084.     case PV_FDM:    return (char_u *)&(curwin->w_p_fdm);
  7085.     case PV_FML:    return (char_u *)&(curwin->w_p_fml);
  7086.     case PV_FDN:    return (char_u *)&(curwin->w_p_fdn);
  7087. # ifdef FEAT_EVAL
  7088.     case PV_FDE:    return (char_u *)&(curwin->w_p_fde);
  7089.     case PV_FDT:    return (char_u *)&(curwin->w_p_fdt);
  7090. # endif
  7091.     case PV_FMR:    return (char_u *)&(curwin->w_p_fmr);
  7092. #endif
  7093.     case PV_NU:    return (char_u *)&(curwin->w_p_nu);
  7094. #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
  7095.     case PV_PVW:    return (char_u *)&(curwin->w_p_pvw);
  7096. #endif
  7097. #ifdef FEAT_RIGHTLEFT
  7098.     case PV_RL:    return (char_u *)&(curwin->w_p_rl);
  7099. #endif
  7100.     case PV_SCROLL:    return (char_u *)&(curwin->w_p_scr);
  7101.     case PV_WRAP:    return (char_u *)&(curwin->w_p_wrap);
  7102. #ifdef FEAT_LINEBREAK
  7103.     case PV_LBR:    return (char_u *)&(curwin->w_p_lbr);
  7104. #endif
  7105. #ifdef FEAT_SCROLLBIND
  7106.     case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
  7107. #endif
  7108.  
  7109.     case PV_AI:    return (char_u *)&(curbuf->b_p_ai);
  7110.     case PV_BIN:    return (char_u *)&(curbuf->b_p_bin);
  7111. #ifdef FEAT_MBYTE
  7112.     case PV_BOMB:    return (char_u *)&(curbuf->b_p_bomb);
  7113. #endif
  7114. #if defined(FEAT_QUICKFIX)
  7115.     case PV_BH:    return (char_u *)&(curbuf->b_p_bh);
  7116.     case PV_BT:    return (char_u *)&(curbuf->b_p_bt);
  7117. #endif
  7118.     case PV_BL:    return (char_u *)&(curbuf->b_p_bl);
  7119. #ifdef FEAT_CINDENT
  7120.     case PV_CIN:    return (char_u *)&(curbuf->b_p_cin);
  7121.     case PV_CINK:    return (char_u *)&(curbuf->b_p_cink);
  7122.     case PV_CINO:    return (char_u *)&(curbuf->b_p_cino);
  7123. #endif
  7124. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  7125.     case PV_CINW:    return (char_u *)&(curbuf->b_p_cinw);
  7126. #endif
  7127. #ifdef FEAT_COMMENTS
  7128.     case PV_COM:    return (char_u *)&(curbuf->b_p_com);
  7129. #endif
  7130. #ifdef FEAT_FOLDING
  7131.     case PV_CMS:    return (char_u *)&(curbuf->b_p_cms);
  7132. #endif
  7133. #ifdef FEAT_INS_EXPAND
  7134.     case PV_CPT:    return (char_u *)&(curbuf->b_p_cpt);
  7135. #endif
  7136.     case PV_EOL:    return (char_u *)&(curbuf->b_p_eol);
  7137.     case PV_ET:    return (char_u *)&(curbuf->b_p_et);
  7138. #ifdef FEAT_MBYTE
  7139.     case PV_FENC:    return (char_u *)&(curbuf->b_p_fenc);
  7140. #endif
  7141.     case PV_FF:    return (char_u *)&(curbuf->b_p_ff);
  7142. #ifdef FEAT_AUTOCMD
  7143.     case PV_FT:    return (char_u *)&(curbuf->b_p_ft);
  7144. #endif
  7145.     case PV_FO:    return (char_u *)&(curbuf->b_p_fo);
  7146.     case PV_IMI:    return (char_u *)&(curbuf->b_p_iminsert);
  7147.     case PV_IMS:    return (char_u *)&(curbuf->b_p_imsearch);
  7148.     case PV_INF:    return (char_u *)&(curbuf->b_p_inf);
  7149.     case PV_ISK:    return (char_u *)&(curbuf->b_p_isk);
  7150. #ifdef FEAT_FIND_ID
  7151. # ifdef FEAT_EVAL
  7152.     case PV_INEX:    return (char_u *)&(curbuf->b_p_inex);
  7153. # endif
  7154. #endif
  7155. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  7156.     case PV_INDE:    return (char_u *)&(curbuf->b_p_inde);
  7157.     case PV_INDK:    return (char_u *)&(curbuf->b_p_indk);
  7158. #endif
  7159. #ifdef FEAT_CRYPT
  7160.     case PV_KEY:    return (char_u *)&(curbuf->b_p_key);
  7161. #endif
  7162. #ifdef FEAT_LISP
  7163.     case PV_LISP:    return (char_u *)&(curbuf->b_p_lisp);
  7164. #endif
  7165.     case PV_ML:    return (char_u *)&(curbuf->b_p_ml);
  7166.     case PV_MPS:    return (char_u *)&(curbuf->b_p_mps);
  7167.     case PV_MA:    return (char_u *)&(curbuf->b_p_ma);
  7168.     case PV_MOD:    return (char_u *)&(curbuf->b_changed);
  7169.     case PV_NF:    return (char_u *)&(curbuf->b_p_nf);
  7170. #ifdef FEAT_OSFILETYPE
  7171.     case PV_OFT:    return (char_u *)&(curbuf->b_p_oft);
  7172. #endif
  7173.     case PV_RO:    return (char_u *)&(curbuf->b_p_ro);
  7174. #ifdef FEAT_SMARTINDENT
  7175.     case PV_SI:    return (char_u *)&(curbuf->b_p_si);
  7176. #endif
  7177. #ifndef SHORT_FNAME
  7178.     case PV_SN:    return (char_u *)&(curbuf->b_p_sn);
  7179. #endif
  7180.     case PV_STS:    return (char_u *)&(curbuf->b_p_sts);
  7181. #ifdef FEAT_SEARCHPATH
  7182.     case PV_SUA:    return (char_u *)&(curbuf->b_p_sua);
  7183. #endif
  7184.     case PV_SWF:    return (char_u *)&(curbuf->b_p_swf);
  7185. #ifdef FEAT_SYN_HL
  7186.     case PV_SYN:    return (char_u *)&(curbuf->b_p_syn);
  7187. #endif
  7188.     case PV_SW:    return (char_u *)&(curbuf->b_p_sw);
  7189.     case PV_TS:    return (char_u *)&(curbuf->b_p_ts);
  7190.     case PV_TW:    return (char_u *)&(curbuf->b_p_tw);
  7191.     case PV_TX:    return (char_u *)&(curbuf->b_p_tx);
  7192.     case PV_WM:    return (char_u *)&(curbuf->b_p_wm);
  7193. #ifdef FEAT_KEYMAP
  7194.     case PV_KMAP:    return (char_u *)&(curbuf->b_p_keymap);
  7195. #endif
  7196.     default:    EMSG(_("E356: get_varp ERROR"));
  7197.     }
  7198.     /* always return a valid pointer to avoid a crash! */
  7199.     return (char_u *)&(curbuf->b_p_wm);
  7200. }
  7201.  
  7202. /*
  7203.  * Get the value of 'equalprg', either the buffer-local one or the global one.
  7204.  */
  7205.     char_u *
  7206. get_equalprg()
  7207. {
  7208.     if (*curbuf->b_p_ep == NUL)
  7209.     return p_ep;
  7210.     return curbuf->b_p_ep;
  7211. }
  7212.  
  7213. #if defined(FEAT_WINDOWS) || defined(PROTO)
  7214. /*
  7215.  * Copy options from one window to another.
  7216.  * Used when splitting a window.
  7217.  */
  7218.     void
  7219. win_copy_options(wp_from, wp_to)
  7220.     win_T    *wp_from;
  7221.     win_T    *wp_to;
  7222. {
  7223.     copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
  7224.     copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
  7225. # ifdef FEAT_RIGHTLEFT
  7226. #  ifdef FEAT_FKMAP
  7227.     /* Is this right? */
  7228.     wp_to->w_farsi = wp_from->w_farsi;
  7229. #  endif
  7230. # endif
  7231. }
  7232. #endif
  7233.  
  7234. /*
  7235.  * Copy the options from one winopt_T to another.
  7236.  * Doesn't free the old option values in "to", use clear_winopt() for that.
  7237.  * The 'scroll' option is not copied, because it depends on the window height.
  7238.  * The 'previewwindow' option is reset, there can be only one preview window.
  7239.  */
  7240.     void
  7241. copy_winopt(from, to)
  7242.     winopt_T    *from;
  7243.     winopt_T    *to;
  7244. {
  7245.     to->wo_list = from->wo_list;
  7246.     to->wo_nu = from->wo_nu;
  7247. #ifdef FEAT_RIGHTLEFT
  7248.     to->wo_rl = from->wo_rl;
  7249. #endif
  7250.     to->wo_wrap = from->wo_wrap;
  7251. #ifdef FEAT_LINEBREAK
  7252.     to->wo_lbr = from->wo_lbr;
  7253. #endif
  7254. #ifdef FEAT_SCROLLBIND
  7255.     to->wo_scb = from->wo_scb;
  7256. #endif
  7257. #ifdef FEAT_DIFF
  7258.     to->wo_diff = from->wo_diff;
  7259. #endif
  7260. #ifdef FEAT_FOLDING
  7261.     to->wo_fdc = from->wo_fdc;
  7262.     to->wo_fen = from->wo_fen;
  7263.     to->wo_fdi = vim_strsave(from->wo_fdi);
  7264.     to->wo_fml = from->wo_fml;
  7265.     to->wo_fdl = from->wo_fdl;
  7266.     to->wo_fdm = vim_strsave(from->wo_fdm);
  7267.     to->wo_fdn = from->wo_fdn;
  7268. # ifdef FEAT_EVAL
  7269.     to->wo_fde = vim_strsave(from->wo_fde);
  7270.     to->wo_fdt = vim_strsave(from->wo_fdt);
  7271. # endif
  7272.     to->wo_fmr = vim_strsave(from->wo_fmr);
  7273. #endif
  7274.     check_winopt(to);        /* don't want NULL pointers */
  7275. }
  7276.  
  7277. /*
  7278.  * Check string options in a window for a NULL value.
  7279.  */
  7280.     void
  7281. check_win_options(win)
  7282.     win_T    *win;
  7283. {
  7284.     check_winopt(&win->w_onebuf_opt);
  7285.     check_winopt(&win->w_allbuf_opt);
  7286. }
  7287.  
  7288. /*
  7289.  * Check for NULL pointers in a winopt_T and replace them with empty_option.
  7290.  */
  7291. /*ARGSUSED*/
  7292.     void
  7293. check_winopt(wop)
  7294.     winopt_T    *wop;
  7295. {
  7296. #ifdef FEAT_FOLDING
  7297.     check_string_option(&wop->wo_fdi);
  7298.     check_string_option(&wop->wo_fdm);
  7299. # ifdef FEAT_EVAL
  7300.     check_string_option(&wop->wo_fde);
  7301.     check_string_option(&wop->wo_fdt);
  7302. # endif
  7303.     check_string_option(&wop->wo_fmr);
  7304. #endif
  7305. }
  7306.  
  7307. /*
  7308.  * Free the allocated memory inside a winopt_T.
  7309.  */
  7310. /*ARGSUSED*/
  7311.     void
  7312. clear_winopt(wop)
  7313.     winopt_T    *wop;
  7314. {
  7315. #ifdef FEAT_FOLDING
  7316.     clear_string_option(&wop->wo_fdi);
  7317.     clear_string_option(&wop->wo_fdm);
  7318. # ifdef FEAT_EVAL
  7319.     clear_string_option(&wop->wo_fde);
  7320.     clear_string_option(&wop->wo_fdt);
  7321. # endif
  7322.     clear_string_option(&wop->wo_fmr);
  7323. #endif
  7324. }
  7325.  
  7326. /*
  7327.  * Copy global option values to local options for one buffer.
  7328.  * Used when creating a new buffer and sometimes when entering a buffer.
  7329.  * flags:
  7330.  * BCO_ENTER    We will enter the buf buffer.
  7331.  * BCO_ALWAYS    Always copy the options, but only set b_p_initialized when
  7332.  *        appropriate.
  7333.  * BCO_NOHELP    Don't copy the values to a help buffer.
  7334.  */
  7335.     void
  7336. buf_copy_options(buf, flags)
  7337.     buf_T    *buf;
  7338.     int        flags;
  7339. {
  7340.     int        should_copy = TRUE;
  7341.     char_u    *save_p_isk = NULL;        /* init for GCC */
  7342.     int        dont_do_help;
  7343.     int        did_isk = FALSE;
  7344.  
  7345.     /*
  7346.      * Don't do anything of the buffer is invalid.
  7347.      */
  7348.     if (buf == NULL || !buf_valid(buf))
  7349.     return;
  7350.  
  7351.     /*
  7352.      * Skip this when the option defaults have not been set yet.  Happens when
  7353.      * main() allocates the first buffer.
  7354.      */
  7355.     if (p_cpo != NULL)
  7356.     {
  7357.     /*
  7358.      * Always copy when entering and 'cpo' contains 'S'.
  7359.      * Don't copy when already initialized.
  7360.      * Don't copy when 'cpo' contains 's' and not entering.
  7361.      * 'S'    BCO_ENTER  initialized    's'  should_copy
  7362.      * yes      yes           X     X    TRUE
  7363.      * yes      no          yes     X    FALSE
  7364.      * no       X          yes     X    FALSE
  7365.      *  X      no          no    yes    FALSE
  7366.      *  X      no          no    no    TRUE
  7367.      * no      yes          no     X    TRUE
  7368.      */
  7369.     if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
  7370.         && (buf->b_p_initialized
  7371.             || (!(flags & BCO_ENTER)
  7372.             && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
  7373.         should_copy = FALSE;
  7374.  
  7375.     if (should_copy || (flags & BCO_ALWAYS))
  7376.     {
  7377.         /* Don't copy the options specific to a help buffer when
  7378.          * BCO_NOHELP is given or the options were initialized already
  7379.          * (jumping back to a help file with CTRL-T or CTRL-O) */
  7380.         dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
  7381.                                || buf->b_p_initialized;
  7382.         if (dont_do_help)        /* don't free b_p_isk */
  7383.         {
  7384.         save_p_isk = buf->b_p_isk;
  7385.         buf->b_p_isk = NULL;
  7386.         }
  7387.         /*
  7388.          * Always free the allocated strings.
  7389.          * If not already initialized, set 'readonly' and copy 'fileformat'.
  7390.          */
  7391.         if (!buf->b_p_initialized)
  7392.         {
  7393.         free_buf_options(buf, TRUE);
  7394.         buf->b_p_ro = FALSE;        /* don't copy readonly */
  7395.         buf->b_p_tx = p_tx;
  7396. #ifdef FEAT_MBYTE
  7397.         buf->b_p_fenc = vim_strsave(p_fenc);
  7398. #endif
  7399.         buf->b_p_ff = vim_strsave(p_ff);
  7400. #if defined(FEAT_QUICKFIX)
  7401.         buf->b_p_bh = empty_option;
  7402.         buf->b_p_bt = empty_option;
  7403. #endif
  7404.         }
  7405.         else
  7406.         free_buf_options(buf, FALSE);
  7407.  
  7408.         buf->b_p_ai = p_ai;
  7409.         buf->b_p_ai_nopaste = p_ai_nopaste;
  7410.         buf->b_p_sw = p_sw;
  7411.         buf->b_p_tw = p_tw;
  7412.         buf->b_p_tw_nopaste = p_tw_nopaste;
  7413.         buf->b_p_tw_nobin = p_tw_nobin;
  7414.         buf->b_p_wm = p_wm;
  7415.         buf->b_p_wm_nopaste = p_wm_nopaste;
  7416.         buf->b_p_wm_nobin = p_wm_nobin;
  7417.         buf->b_p_bin = p_bin;
  7418.         buf->b_p_et = p_et;
  7419.         buf->b_p_et_nobin = p_et_nobin;
  7420.         buf->b_p_ml = p_ml;
  7421.         buf->b_p_ml_nobin = p_ml_nobin;
  7422.         buf->b_p_inf = p_inf;
  7423.         buf->b_p_swf = p_swf;
  7424. #ifdef FEAT_INS_EXPAND
  7425.         buf->b_p_cpt = vim_strsave(p_cpt);
  7426. #endif
  7427.         buf->b_p_sts = p_sts;
  7428.         buf->b_p_sts_nopaste = p_sts_nopaste;
  7429. #ifndef SHORT_FNAME
  7430.         buf->b_p_sn = p_sn;
  7431. #endif
  7432. #ifdef FEAT_COMMENTS
  7433.         buf->b_p_com = vim_strsave(p_com);
  7434. #endif
  7435. #ifdef FEAT_FOLDING
  7436.         buf->b_p_cms = vim_strsave(p_cms);
  7437. #endif
  7438.         buf->b_p_fo = vim_strsave(p_fo);
  7439.         buf->b_p_nf = vim_strsave(p_nf);
  7440.         buf->b_p_mps = vim_strsave(p_mps);
  7441. #ifdef FEAT_SMARTINDENT
  7442.         buf->b_p_si = p_si;
  7443. #endif
  7444. #ifdef FEAT_CINDENT
  7445.         buf->b_p_cin = p_cin;
  7446.         buf->b_p_cink = vim_strsave(p_cink);
  7447.         buf->b_p_cino = vim_strsave(p_cino);
  7448. #endif
  7449. #ifdef FEAT_AUTOCMD
  7450.         /* Don't copy 'filetype', it must be detected */
  7451.         buf->b_p_ft = empty_option;
  7452. #endif
  7453. #ifdef FEAT_OSFILETYPE
  7454.         buf->b_p_oft = vim_strsave(p_oft);
  7455. #endif
  7456. #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
  7457.         buf->b_p_cinw = vim_strsave(p_cinw);
  7458. #endif
  7459. #ifdef FEAT_LISP
  7460.         buf->b_p_lisp = p_lisp;
  7461. #endif
  7462. #ifdef FEAT_SYN_HL
  7463.         /* Don't copy 'syntax', it must be set */
  7464.         buf->b_p_syn = empty_option;
  7465. #endif
  7466. #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
  7467.         buf->b_p_inde = vim_strsave(p_inde);
  7468.         buf->b_p_indk = vim_strsave(p_indk);
  7469. #endif
  7470. #ifdef FEAT_CRYPT
  7471.         buf->b_p_key = vim_strsave(p_key);
  7472. #endif
  7473. #ifdef FEAT_SEARCHPATH
  7474.         buf->b_p_sua = vim_strsave(p_sua);
  7475. #endif
  7476. #ifdef FEAT_KEYMAP
  7477.         buf->b_p_keymap = vim_strsave(p_keymap);
  7478.         buf->b_kmap_state |= KEYMAP_INIT;
  7479. #endif
  7480.         /* This isn't really an option, but copying the langmap and IME
  7481.          * state from the current buffer is better than resetting it. */
  7482.         buf->b_p_iminsert = p_iminsert;
  7483.         buf->b_p_imsearch = p_imsearch;
  7484.  
  7485.         /* options that are normally global but also have a local value
  7486.          * are not copied, start using the global value */
  7487.         buf->b_p_ar = -1;
  7488. #ifdef FEAT_QUICKFIX
  7489.         buf->b_p_gp = empty_option;
  7490.         buf->b_p_mp = empty_option;
  7491.         buf->b_p_efm = empty_option;
  7492. #endif
  7493.         buf->b_p_ep = empty_option;
  7494.         buf->b_p_path = empty_option;
  7495.         buf->b_p_tags = empty_option;
  7496. #ifdef FEAT_FIND_ID
  7497.         buf->b_p_def = empty_option;
  7498.         buf->b_p_inc = empty_option;
  7499. # ifdef FEAT_EVAL
  7500.         buf->b_p_inex = vim_strsave(p_inex);
  7501. # endif
  7502. #endif
  7503. #ifdef FEAT_INS_EXPAND
  7504.         buf->b_p_dict = empty_option;
  7505.         buf->b_p_tsr = empty_option;
  7506. #endif
  7507.  
  7508.         /*
  7509.          * Don't copy the options set by ex_help(), use the saved values,
  7510.          * when going from a help buffer to a non-help buffer.
  7511.          * Don't touch these at all when BCO_NOHELP is used and going from
  7512.          * or to a help buffer.
  7513.          */
  7514.         if (dont_do_help)
  7515.         buf->b_p_isk = save_p_isk;
  7516.         else
  7517.         {
  7518.         buf->b_p_isk = vim_strsave(p_isk);
  7519.         did_isk = TRUE;
  7520.         buf->b_p_ts = p_ts;
  7521.         buf->b_help = FALSE;
  7522. #ifdef FEAT_QUICKFIX
  7523.         if (buf->b_p_bt[0] == 'h')
  7524.             clear_string_option(&buf->b_p_bt);
  7525. #endif
  7526.         buf->b_p_ma = p_ma;
  7527.         }
  7528.     }
  7529.  
  7530.     /*
  7531.      * When the options should be copied (ignoring BCO_ALWAYS), set the
  7532.      * flag that indicates that the options have been initialized.
  7533.      */
  7534.     if (should_copy)
  7535.         buf->b_p_initialized = TRUE;
  7536.     }
  7537.  
  7538.     check_buf_options(buf);        /* make sure we don't have NULLs */
  7539.     if (did_isk)
  7540.     (void)buf_init_chartab(buf, FALSE);
  7541. }
  7542.  
  7543. /*
  7544.  * Reset the 'modifiable' option and its default value.
  7545.  */
  7546.     void
  7547. reset_modifiable()
  7548. {
  7549.     int        opt_idx;
  7550.  
  7551.     curbuf->b_p_ma = FALSE;
  7552.     p_ma = FALSE;
  7553.     opt_idx = findoption((char_u *)"ma");
  7554.     options[opt_idx].def_val[VI_DEFAULT] = FALSE;
  7555. }
  7556.  
  7557. /*
  7558.  * Set the global value for 'iminsert' to the local value.
  7559.  */
  7560.     void
  7561. set_iminsert_global()
  7562. {
  7563.     p_iminsert = curbuf->b_p_iminsert;
  7564. }
  7565.  
  7566. /*
  7567.  * Set the global value for 'imsearch' to the local value.
  7568.  */
  7569.     void
  7570. set_imsearch_global()
  7571. {
  7572.     p_imsearch = curbuf->b_p_imsearch;
  7573. }
  7574.  
  7575. #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
  7576. static int expand_option_idx = -1;
  7577. static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
  7578. static int expand_option_flags = 0;
  7579.  
  7580.     void
  7581. set_context_in_set_cmd(xp, arg, opt_flags)
  7582.     expand_T    *xp;
  7583.     char_u    *arg;
  7584.     int        opt_flags;    /* OPT_GLOBAL and/or OPT_LOCAL */
  7585. {
  7586.     int        nextchar;
  7587.     long_u    flags = 0;    /* init for GCC */
  7588.     int        opt_idx = 0;    /* init for GCC */
  7589.     char_u    *p;
  7590.     char_u    *s;
  7591.     char_u    *after_blank = NULL;
  7592.     int        is_term_option = FALSE;
  7593.     int        key;
  7594.  
  7595.     expand_option_flags = opt_flags;
  7596.  
  7597.     xp->xp_context = EXPAND_SETTINGS;
  7598.     if (*arg == NUL)
  7599.     {
  7600.     xp->xp_pattern = arg;
  7601.     return;
  7602.     }
  7603.     p = arg + STRLEN(arg) - 1;
  7604.     if (*p == ' ' && *(p - 1) != '\\')
  7605.     {
  7606.     xp->xp_pattern = p + 1;
  7607.     return;
  7608.     }
  7609.     while (p > arg)
  7610.     {
  7611.     s = p;
  7612.     /* count number of backslashes before ' ' or ',' */
  7613.     if (*p == ' ' || *p == ',')
  7614.     {
  7615.         while (s > arg && *(s - 1) == '\\')
  7616.         --s;
  7617.     }
  7618.     /* break at a space with an even number of backslashes */
  7619.     if (*p == ' ' && ((p - s) & 1) == 0)
  7620.     {
  7621.         ++p;
  7622.         break;
  7623.     }
  7624.     /* remember possible start of file name to expand */
  7625.     if (after_blank == NULL
  7626.         && ((*p == ' ' && (p - s) < 2)
  7627.             || (*p == ',' && p == s)))
  7628.         after_blank = p + 1;
  7629.     --p;
  7630.     }
  7631.     if (STRNCMP(p, "no", 2) == 0)
  7632.     {
  7633.     xp->xp_context = EXPAND_BOOL_SETTINGS;
  7634.     p += 2;
  7635.     }
  7636.     if (STRNCMP(p, "inv", 3) == 0)
  7637.     {
  7638.     xp->xp_context = EXPAND_BOOL_SETTINGS;
  7639.     p += 3;
  7640.     }
  7641.     xp->xp_pattern = arg = p;
  7642.     if (*arg == '<')
  7643.     {
  7644.     while (*p != '>')
  7645.         if (*p++ == NUL)        /* expand terminal option name */
  7646.         return;
  7647.     key = get_special_key_code(arg + 1);
  7648.     if (key == 0)            /* unknown name */
  7649.     {
  7650.         xp->xp_context = EXPAND_NOTHING;
  7651.         return;
  7652.     }
  7653.     nextchar = *++p;
  7654.     is_term_option = TRUE;
  7655.     expand_option_name[2] = KEY2TERMCAP0(key);
  7656.     expand_option_name[3] = KEY2TERMCAP1(key);
  7657.     }
  7658.     else
  7659.     {
  7660.     if (p[0] == 't' && p[1] == '_')
  7661.     {
  7662.         p += 2;
  7663.         if (*p != NUL)
  7664.         ++p;
  7665.         if (*p == NUL)
  7666.         return;        /* expand option name */
  7667.         nextchar = *++p;
  7668.         is_term_option = TRUE;
  7669.         expand_option_name[2] = p[-2];
  7670.         expand_option_name[3] = p[-1];
  7671.     }
  7672.     else
  7673.     {
  7674.         /* Allow * wildcard */
  7675.         while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
  7676.         p++;
  7677.         if (*p == NUL)
  7678.         return;
  7679.         nextchar = *p;
  7680.         *p = NUL;
  7681.         opt_idx = findoption(arg);
  7682.         *p = nextchar;
  7683.         if (opt_idx == -1 || options[opt_idx].var == NULL)
  7684.         {
  7685.         xp->xp_context = EXPAND_NOTHING;
  7686.         return;
  7687.         }
  7688.         flags = options[opt_idx].flags;
  7689.         if (flags & P_BOOL)
  7690.         {
  7691.         xp->xp_context = EXPAND_NOTHING;
  7692.         return;
  7693.         }
  7694.     }
  7695.     }
  7696.     /* handle "-=" and "+=" */
  7697.     if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
  7698.     {
  7699.     ++p;
  7700.     nextchar = '=';
  7701.     }
  7702.     if ((nextchar != '=' && nextchar != ':')
  7703.                     || xp->xp_context == EXPAND_BOOL_SETTINGS)
  7704.     {
  7705.     xp->xp_context = EXPAND_UNSUCCESSFUL;
  7706.     return;
  7707.     }
  7708.     if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
  7709.     {
  7710.     xp->xp_context = EXPAND_OLD_SETTING;
  7711.     if (is_term_option)
  7712.         expand_option_idx = -1;
  7713.     else
  7714.         expand_option_idx = opt_idx;
  7715.     xp->xp_pattern = p + 1;
  7716.     return;
  7717.     }
  7718.     xp->xp_context = EXPAND_NOTHING;
  7719.     if (is_term_option || (flags & P_NUM))
  7720.     return;
  7721.     if (after_blank != NULL)
  7722.     xp->xp_pattern = after_blank;
  7723.     else
  7724.     xp->xp_pattern = p + 1;
  7725.     if (flags & P_EXPAND)
  7726.     {
  7727.     p = options[opt_idx].var;
  7728.     if (p == (char_u *)&p_bdir
  7729.         || p == (char_u *)&p_dir
  7730.         || p == (char_u *)&p_path
  7731.         || p == (char_u *)&p_rtp
  7732. #ifdef FEAT_SEARCHPATH
  7733.         || p == (char_u *)&p_cdpath
  7734. #endif
  7735. #ifdef FEAT_SESSION
  7736.         || p == (char_u *)&p_vdir
  7737. #endif
  7738.         )
  7739.     {
  7740.         xp->xp_context = EXPAND_DIRECTORIES;
  7741.         if (p == (char_u *)&p_path
  7742. #ifdef FEAT_SEARCHPATH
  7743.             || p == (char_u *)&p_cdpath
  7744. #endif
  7745.            )
  7746.         xp->xp_set_path = TRUE;
  7747.     }
  7748.     else
  7749.         xp->xp_context = EXPAND_FILES;
  7750.     }
  7751.     return;
  7752. }
  7753.  
  7754.     int
  7755. ExpandSettings(xp, regmatch, num_file, file)
  7756.     expand_T    *xp;
  7757.     regmatch_T    *regmatch;
  7758.     int        *num_file;
  7759.     char_u    ***file;
  7760. {
  7761.     int        num_normal = 0;        /* Nr of matching non-term-code settings */
  7762.     int        num_term = 0;        /* Nr of matching terminal code settings */
  7763.     int        opt_idx;
  7764.     int        match;
  7765.     int        count = 0;
  7766.     char_u    *str;
  7767.     int        loop;
  7768.     int        is_term_opt;
  7769.     char_u    name_buf[MAX_KEY_NAME_LEN];
  7770.     static char *(names[]) = {"all", "termcap"};
  7771.     int        ic = regmatch->rm_ic;    /* remember the ignore-case flag */
  7772.  
  7773.     /* do this loop twice:
  7774.      * loop == 0: count the number of matching options
  7775.      * loop == 1: copy the matching options into allocated memory
  7776.      */
  7777.     for (loop = 0; loop <= 1; ++loop)
  7778.     {
  7779.     regmatch->rm_ic = ic;
  7780.     if (xp->xp_context != EXPAND_BOOL_SETTINGS)
  7781.     {
  7782.         for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
  7783.         if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
  7784.         {
  7785.             if (loop == 0)
  7786.             num_normal++;
  7787.             else
  7788.             (*file)[count++] = vim_strsave((char_u *)names[match]);
  7789.         }
  7790.     }
  7791.     for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
  7792.                                     opt_idx++)
  7793.     {
  7794.         if (options[opt_idx].var == NULL)
  7795.         continue;
  7796.         if (xp->xp_context == EXPAND_BOOL_SETTINGS
  7797.           && !(options[opt_idx].flags & P_BOOL))
  7798.         continue;
  7799.         is_term_opt = istermoption(&options[opt_idx]);
  7800.         if (is_term_opt && num_normal > 0)
  7801.         continue;
  7802.         match = FALSE;
  7803.         if (vim_regexec(regmatch, str, (colnr_T)0)
  7804.             || (options[opt_idx].shortname != NULL
  7805.             && vim_regexec(regmatch,
  7806.                (char_u *)options[opt_idx].shortname, (colnr_T)0)))
  7807.         match = TRUE;
  7808.         else if (is_term_opt)
  7809.         {
  7810.         name_buf[0] = '<';
  7811.         name_buf[1] = 't';
  7812.         name_buf[2] = '_';
  7813.         name_buf[3] = str[2];
  7814.         name_buf[4] = str[3];
  7815.         name_buf[5] = '>';
  7816.         name_buf[6] = NUL;
  7817.         if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  7818.         {
  7819.             match = TRUE;
  7820.             str = name_buf;
  7821.         }
  7822.         }
  7823.         if (match)
  7824.         {
  7825.         if (loop == 0)
  7826.         {
  7827.             if (is_term_opt)
  7828.             num_term++;
  7829.             else
  7830.             num_normal++;
  7831.         }
  7832.         else
  7833.             (*file)[count++] = vim_strsave(str);
  7834.         }
  7835.     }
  7836.     /*
  7837.      * Check terminal key codes, these are not in the option table
  7838.      */
  7839.     if (xp->xp_context != EXPAND_BOOL_SETTINGS  && num_normal == 0)
  7840.     {
  7841.         for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
  7842.         {
  7843.         if (!isprint(str[0]) || !isprint(str[1]))
  7844.             continue;
  7845.  
  7846.         name_buf[0] = 't';
  7847.         name_buf[1] = '_';
  7848.         name_buf[2] = str[0];
  7849.         name_buf[3] = str[1];
  7850.         name_buf[4] = NUL;
  7851.  
  7852.         match = FALSE;
  7853.         if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  7854.             match = TRUE;
  7855.         else
  7856.         {
  7857.             name_buf[0] = '<';
  7858.             name_buf[1] = 't';
  7859.             name_buf[2] = '_';
  7860.             name_buf[3] = str[0];
  7861.             name_buf[4] = str[1];
  7862.             name_buf[5] = '>';
  7863.             name_buf[6] = NUL;
  7864.  
  7865.             if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  7866.             match = TRUE;
  7867.         }
  7868.         if (match)
  7869.         {
  7870.             if (loop == 0)
  7871.             num_term++;
  7872.             else
  7873.             (*file)[count++] = vim_strsave(name_buf);
  7874.         }
  7875.         }
  7876.  
  7877.         /*
  7878.          * Check special key names.
  7879.          */
  7880.         regmatch->rm_ic = TRUE;        /* ignore case here */
  7881.         for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
  7882.         {
  7883.         name_buf[0] = '<';
  7884.         STRCPY(name_buf + 1, str);
  7885.         STRCAT(name_buf, ">");
  7886.  
  7887.         if (vim_regexec(regmatch, name_buf, (colnr_T)0))
  7888.         {
  7889.             if (loop == 0)
  7890.             num_term++;
  7891.             else
  7892.             (*file)[count++] = vim_strsave(name_buf);
  7893.         }
  7894.         }
  7895.     }
  7896.     if (loop == 0)
  7897.     {
  7898.         if (num_normal > 0)
  7899.         *num_file = num_normal;
  7900.         else if (num_term > 0)
  7901.         *num_file = num_term;
  7902.         else
  7903.         return OK;
  7904.         *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
  7905.         if (*file == NULL)
  7906.         {
  7907.         *file = (char_u **)"";
  7908.         return FAIL;
  7909.         }
  7910.     }
  7911.     }
  7912.     return OK;
  7913. }
  7914.  
  7915.     int
  7916. ExpandOldSetting(num_file, file)
  7917.     int        *num_file;
  7918.     char_u  ***file;
  7919. {
  7920.     char_u  *var = NULL;    /* init for GCC */
  7921.     char_u  *buf;
  7922.  
  7923.     *num_file = 0;
  7924.     *file = (char_u **)alloc((unsigned)sizeof(char_u *));
  7925.     if (*file == NULL)
  7926.     return FAIL;
  7927.  
  7928.     /*
  7929.      * For a terminal key code expand_option_idx is < 0.
  7930.      */
  7931.     if (expand_option_idx < 0)
  7932.     {
  7933.     var = find_termcode(expand_option_name + 2);
  7934.     if (var == NULL)
  7935.         expand_option_idx = findoption(expand_option_name);
  7936.     }
  7937.  
  7938.     if (expand_option_idx >= 0)
  7939.     {
  7940.     /* put string of option value in NameBuff */
  7941.     option_value2string(&options[expand_option_idx], expand_option_flags);
  7942.     var = NameBuff;
  7943.     }
  7944.     else if (var == NULL)
  7945.     var = (char_u *)"";
  7946.  
  7947.     /* A backslash is required before some characters */
  7948.     buf = vim_strsave_escaped(var, escape_chars);
  7949.  
  7950.     if (buf == NULL)
  7951.     {
  7952.     vim_free(*file);
  7953.     *file = NULL;
  7954.     return FAIL;
  7955.     }
  7956.  
  7957.     *file[0] = buf;
  7958.     *num_file = 1;
  7959.     return OK;
  7960. }
  7961. #endif
  7962.  
  7963. /*
  7964.  * Get the value for the numeric or string option *opp in a nice format into
  7965.  * NameBuff[].  Must not be called with a hidden option!
  7966.  */
  7967.     static void
  7968. option_value2string(opp, opt_flags)
  7969.     struct vimoption    *opp;
  7970.     int            opt_flags;    /* OPT_GLOBAL and/or OPT_LOCAL */
  7971. {
  7972.     char_u    *varp;
  7973.  
  7974.     varp = get_varp_scope(opp, opt_flags);
  7975.  
  7976.     if (opp->flags & P_NUM)
  7977.     {
  7978.     long wc = 0;
  7979.  
  7980.     if (wc_use_keyname(varp, &wc))
  7981.         STRCPY(NameBuff, get_special_key_name((int)wc, 0));
  7982.     else if (wc != 0)
  7983.         STRCPY(NameBuff, transchar((int)wc));
  7984.     else
  7985.         sprintf((char *)NameBuff, "%ld", *(long *)varp);
  7986.     }
  7987.     else    /* P_STRING */
  7988.     {
  7989.     varp = *(char_u **)(varp);
  7990.     if (varp == NULL)            /* just in case */
  7991.         NameBuff[0] = NUL;
  7992. #ifdef FEAT_CRYPT
  7993.     /* don't show the actual value of 'key', only that it's set */
  7994.     if (opp->var == (char_u *)&p_key && *varp)
  7995.         STRCPY(NameBuff, "*****");
  7996. #endif
  7997.     else if (opp->flags & P_EXPAND)
  7998.         home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
  7999.     /* Translate 'pastetoggle' into special key names */
  8000.     else if ((char_u **)opp->var == &p_pt)
  8001.         str2specialbuf(p_pt, NameBuff, MAXPATHL);
  8002.     else
  8003.         STRNCPY(NameBuff, varp, MAXPATHL);
  8004.     }
  8005. }
  8006.  
  8007. /*
  8008.  * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
  8009.  * printed as a keyname.
  8010.  * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
  8011.  */
  8012.     static int
  8013. wc_use_keyname(varp, wcp)
  8014.     char_u    *varp;
  8015.     long    *wcp;
  8016. {
  8017.     if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
  8018.     {
  8019.     *wcp = *(long *)varp;
  8020.     if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
  8021.         return TRUE;
  8022.     }
  8023.     return FALSE;
  8024. }
  8025.  
  8026. #ifdef FEAT_LANGMAP
  8027. /*
  8028.  * Any character has an equivalent character.  This is used for keyboards that
  8029.  * have a special language mode that sends characters above 128 (although
  8030.  * other characters can be translated too).
  8031.  */
  8032.  
  8033. /*
  8034.  * char_u langmap_mapchar[256];
  8035.  * Normally maps each of the 128 upper chars to an <128 ascii char; used to
  8036.  * "translate" native lang chars in normal mode or some cases of
  8037.  * insert mode without having to tediously switch lang mode back&forth.
  8038.  */
  8039.  
  8040.     static void
  8041. langmap_init()
  8042. {
  8043.     int i;
  8044.  
  8045.     for (i = 0; i < 256; i++)        /* we init with a-one-to one map */
  8046.     langmap_mapchar[i] = i;
  8047. }
  8048.  
  8049. /*
  8050.  * Called when langmap option is set; the language map can be
  8051.  * changed at any time!
  8052.  */
  8053.     static void
  8054. langmap_set()
  8055. {
  8056.     char_u  *p;
  8057.     char_u  *p2;
  8058.     int        from, to;
  8059.  
  8060.     langmap_init();                /* back to one-to-one map first */
  8061.  
  8062.     for (p = p_langmap; p[0] != NUL; )
  8063.     {
  8064.     for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; ++p2)
  8065.     {
  8066.         if (p2[0] == '\\' && p2[1] != NUL)
  8067.         ++p2;
  8068. #ifdef FEAT_MBYTE
  8069.         p2 += (*mb_ptr2len_check)(p2) - 1;
  8070. #endif
  8071.     }
  8072.     if (p2[0] == ';')
  8073.         ++p2;        /* abcd;ABCD form, p2 points to A */
  8074.     else
  8075.         p2 = NULL;        /* aAbBcCdD form, p2 is NULL */
  8076.     while (p[0])
  8077.     {
  8078.         if (p[0] == '\\' && p[1] != NUL)
  8079.         ++p;
  8080. #ifdef FEAT_MBYTE
  8081.         from = (*mb_ptr2char)(p);
  8082. #else
  8083.         from = p[0];
  8084. #endif
  8085.         if (p2 == NULL)
  8086.         {
  8087. #ifdef FEAT_MBYTE
  8088.         p += (*mb_ptr2len_check)(p);
  8089. #else
  8090.         ++p;
  8091. #endif
  8092.         if (p[0] == '\\')
  8093.             ++p;
  8094. #ifdef FEAT_MBYTE
  8095.         to = (*mb_ptr2char)(p);
  8096. #else
  8097.         to = p[0];
  8098. #endif
  8099.         }
  8100.         else
  8101.         {
  8102.         if (p2[0] == '\\')
  8103.             ++p2;
  8104. #ifdef FEAT_MBYTE
  8105.         to = (*mb_ptr2char)(p2);
  8106. #else
  8107.         to = p2[0];
  8108. #endif
  8109.         }
  8110.         if (to == NUL)
  8111.         {
  8112.         EMSG2(_("E357: 'langmap': Matching character missing for %s"),
  8113.                                  transchar(from));
  8114.         return;
  8115.         }
  8116.         langmap_mapchar[from & 255] = to;
  8117.  
  8118.         /* Advance to next pair */
  8119. #ifdef FEAT_MBYTE
  8120.         p += (*mb_ptr2len_check)(p);
  8121. #else
  8122.         ++p;
  8123. #endif
  8124.         if (p2 == NULL)
  8125.         {
  8126.         if (p[0] == ',')
  8127.         {
  8128.             ++p;
  8129.             break;
  8130.         }
  8131.         }
  8132.         else
  8133.         {
  8134. #ifdef FEAT_MBYTE
  8135.         p2 += (*mb_ptr2len_check)(p2);
  8136. #else
  8137.         ++p2;
  8138. #endif
  8139.         if (*p == ';')
  8140.         {
  8141.             p = p2;
  8142.             if (p[0] != NUL)
  8143.             {
  8144.             if (p[0] != ',')
  8145.             {
  8146.                 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
  8147.                 return;
  8148.             }
  8149.             ++p;
  8150.             }
  8151.             break;
  8152.         }
  8153.         }
  8154.     }
  8155.     }
  8156. }
  8157. #endif
  8158.  
  8159. /*
  8160.  * Return TRUE if format option 'x' is in effect.
  8161.  * Take care of no formatting when 'paste' is set.
  8162.  */
  8163.     int
  8164. has_format_option(x)
  8165.     int        x;
  8166. {
  8167.     if (p_paste)
  8168.     return FALSE;
  8169.     return (vim_strchr(curbuf->b_p_fo, x) != NULL);
  8170. }
  8171.  
  8172. /*
  8173.  * Return TRUE if "x" is present in 'shortmess' option, or
  8174.  * 'shortmess' contains 'a' and "x" is present in SHM_A.
  8175.  */
  8176.     int
  8177. shortmess(x)
  8178.     int        x;
  8179. {
  8180.     return (   vim_strchr(p_shm, x) != NULL
  8181.         || (vim_strchr(p_shm, 'a') != NULL
  8182.         && vim_strchr((char_u *)SHM_A, x) != NULL));
  8183. }
  8184.  
  8185. /*
  8186.  * paste_option_changed() - Called after p_paste was set or reset.
  8187.  */
  8188.     static void
  8189. paste_option_changed()
  8190. {
  8191.     static int    old_p_paste = FALSE;
  8192.     static int    save_sm = 0;
  8193. #ifdef FEAT_CMDL_INFO
  8194.     static int    save_ru = 0;
  8195. #endif
  8196. #ifdef FEAT_RIGHTLEFT
  8197.     static int    save_ri = 0;
  8198.     static int    save_hkmap = 0;
  8199. #endif
  8200.     buf_T    *buf;
  8201.  
  8202.     if (p_paste)
  8203.     {
  8204.     /*
  8205.      * Paste switched from off to on.
  8206.      * Save the current values, so they can be restored later.
  8207.      */
  8208.     if (!old_p_paste)
  8209.     {
  8210.         /* save options for each buffer */
  8211.         for (buf = firstbuf; buf != NULL; buf = buf->b_next)
  8212.         {
  8213.         buf->b_p_tw_nopaste = buf->b_p_tw;
  8214.         buf->b_p_wm_nopaste = buf->b_p_wm;
  8215.         buf->b_p_sts_nopaste = buf->b_p_sts;
  8216.         buf->b_p_ai_nopaste = buf->b_p_ai;
  8217.         }
  8218.  
  8219.         /* save global options */
  8220.         save_sm = p_sm;
  8221. #ifdef FEAT_CMDL_INFO
  8222.         save_ru = p_ru;
  8223. #endif
  8224. #ifdef FEAT_RIGHTLEFT
  8225.         save_ri = p_ri;
  8226.         save_hkmap = p_hkmap;
  8227. #endif
  8228.         /* save global values for local buffer options */
  8229.         p_tw_nopaste = p_tw;
  8230.         p_wm_nopaste = p_wm;
  8231.         p_sts_nopaste = p_sts;
  8232.         p_ai_nopaste = p_ai;
  8233.     }
  8234.  
  8235.     /*
  8236.      * Always set the option values, also when 'paste' is set when it is
  8237.      * already on.
  8238.      */
  8239.     /* set options for each buffer */
  8240.     for (buf = firstbuf; buf != NULL; buf = buf->b_next)
  8241.     {
  8242.         buf->b_p_tw = 0;        /* textwidth is 0 */
  8243.         buf->b_p_wm = 0;        /* wrapmargin is 0 */
  8244.         buf->b_p_sts = 0;        /* softtabstop is 0 */
  8245.         buf->b_p_ai = 0;        /* no auto-indent */
  8246.     }
  8247.  
  8248.     /* set global options */
  8249.     p_sm = 0;            /* no showmatch */
  8250. #ifdef FEAT_CMDL_INFO
  8251. # ifdef FEAT_WINDOWS
  8252.     if (p_ru)
  8253.         status_redraw_all();    /* redraw to remove the ruler */
  8254. # endif
  8255.     p_ru = 0;            /* no ruler */
  8256. #endif
  8257. #ifdef FEAT_RIGHTLEFT
  8258.     p_ri = 0;            /* no reverse insert */
  8259.     p_hkmap = 0;            /* no Hebrew keyboard */
  8260. #endif
  8261.     /* set global values for local buffer options */
  8262.     p_tw = 0;
  8263.     p_wm = 0;
  8264.     p_sts = 0;
  8265.     p_ai = 0;
  8266.     }
  8267.  
  8268.     /*
  8269.      * Paste switched from on to off: Restore saved values.
  8270.      */
  8271.     else if (old_p_paste)
  8272.     {
  8273.     /* restore options for each buffer */
  8274.     for (buf = firstbuf; buf != NULL; buf = buf->b_next)
  8275.     {
  8276.         buf->b_p_tw = buf->b_p_tw_nopaste;
  8277.         buf->b_p_wm = buf->b_p_wm_nopaste;
  8278.         buf->b_p_sts = buf->b_p_sts_nopaste;
  8279.         buf->b_p_ai = buf->b_p_ai_nopaste;
  8280.     }
  8281.  
  8282.     /* restore global options */
  8283.     p_sm = save_sm;
  8284. #ifdef FEAT_CMDL_INFO
  8285. # ifdef FEAT_WINDOWS
  8286.     if (p_ru != save_ru)
  8287.         status_redraw_all();    /* redraw to draw the ruler */
  8288. # endif
  8289.     p_ru = save_ru;
  8290. #endif
  8291. #ifdef FEAT_RIGHTLEFT
  8292.     p_ri = save_ri;
  8293.     p_hkmap = save_hkmap;
  8294. #endif
  8295.     /* set global values for local buffer options */
  8296.     p_tw = p_tw_nopaste;
  8297.     p_wm = p_wm_nopaste;
  8298.     p_sts = p_sts_nopaste;
  8299.     p_ai = p_ai_nopaste;
  8300.     }
  8301.  
  8302.     old_p_paste = p_paste;
  8303. }
  8304.  
  8305. /*
  8306.  * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
  8307.  *
  8308.  * Reset 'compatible' and set the values for options that didn't get set yet
  8309.  * to the Vim defaults.
  8310.  * Don't do this if the 'compatible' option has been set or reset before.
  8311.  */
  8312.     void
  8313. vimrc_found()
  8314. {
  8315.     int        opt_idx;
  8316.  
  8317.     if (!option_was_set((char_u *)"cp"))
  8318.     {
  8319.     p_cp = FALSE;
  8320.     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
  8321.         if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
  8322.         set_option_default(opt_idx, OPT_FREE, FALSE);
  8323.     didset_options();
  8324.     }
  8325. }
  8326.  
  8327. /*
  8328.  * Set 'compatible' on or off.  Called for "-C" and "-N" command line arg.
  8329.  */
  8330.     void
  8331. change_compatible(on)
  8332.     int        on;
  8333. {
  8334.     if (p_cp != on)
  8335.     {
  8336.     p_cp = on;
  8337.     compatible_set();
  8338.     }
  8339.     options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
  8340. }
  8341.  
  8342. /*
  8343.  * Return TRUE when option "name" has been set.
  8344.  */
  8345.     int
  8346. option_was_set(name)
  8347.     char_u    *name;
  8348. {
  8349.     int idx;
  8350.  
  8351.     idx = findoption(name);
  8352.     if (idx < 0)    /* unknown option */
  8353.     return FALSE;
  8354.     if (options[idx].flags & P_WAS_SET)
  8355.     return TRUE;
  8356.     return FALSE;
  8357. }
  8358.  
  8359. /*
  8360.  * compatible_set() - Called when 'compatible' has been set or unset.
  8361.  *
  8362.  * When 'compatible' set: Set all relevant options (those that have the P_VIM)
  8363.  * flag) to a Vi compatible value.
  8364.  * When 'compatible' is unset: Set all options that have a different default
  8365.  * for Vim (without the P_VI_DEF flag) to that default.
  8366.  */
  8367.     static void
  8368. compatible_set()
  8369. {
  8370.     int        opt_idx;
  8371.  
  8372.     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
  8373.     if (       ((options[opt_idx].flags & P_VIM) && p_cp)
  8374.         || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
  8375.         set_option_default(opt_idx, OPT_FREE, p_cp);
  8376.     didset_options();
  8377. }
  8378.  
  8379. #ifdef FEAT_LINEBREAK
  8380.  
  8381. # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
  8382.    /* Borland C++ screws up loop optimisation here (negri) */
  8383. #  pragma option -O-l
  8384. # endif
  8385.  
  8386. /*
  8387.  * fill_breakat_flags() -- called when 'breakat' changes value.
  8388.  */
  8389.     static void
  8390. fill_breakat_flags()
  8391. {
  8392.     char_u    *c;
  8393.     int        i;
  8394.  
  8395.     for (i = 0; i < 256; i++)
  8396.     breakat_flags[i] = FALSE;
  8397.  
  8398.     if (p_breakat != NULL)
  8399.     for (c = p_breakat; *c; c++)
  8400.         breakat_flags[*c] = TRUE;
  8401. }
  8402.  
  8403. # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
  8404. #  pragma option -O.l
  8405. # endif
  8406.  
  8407. #endif
  8408.  
  8409. /*
  8410.  * Check an option that can be a range of string values.
  8411.  *
  8412.  * Return OK for correct value, FAIL otherwise.
  8413.  * Empty is always OK.
  8414.  */
  8415.     static int
  8416. check_opt_strings(val, values, list)
  8417.     char_u    *val;
  8418.     char    **values;
  8419.     int        list;        /* when TRUE: accept a list of values */
  8420. {
  8421.     return opt_strings_flags(val, values, NULL, list);
  8422. }
  8423.  
  8424. /*
  8425.  * Handle an option that can be a range of string values.
  8426.  * Set a flag in "*flagp" for each string present.
  8427.  *
  8428.  * Return OK for correct value, FAIL otherwise.
  8429.  * Empty is always OK.
  8430.  */
  8431.     static int
  8432. opt_strings_flags(val, values, flagp, list)
  8433.     char_u    *val;        /* new value */
  8434.     char    **values;    /* array of valid string values */
  8435.     unsigned    *flagp;
  8436.     int        list;        /* when TRUE: accept a list of values */
  8437. {
  8438.     int        i;
  8439.     int        len;
  8440.     unsigned    new_flags = 0;
  8441.  
  8442.     while (*val)
  8443.     {
  8444.     for (i = 0; ; ++i)
  8445.     {
  8446.         if (values[i] == NULL)    /* val not found in values[] */
  8447.         return FAIL;
  8448.  
  8449.         len = (int)STRLEN(values[i]);
  8450.         if (STRNCMP(values[i], val, len) == 0
  8451.             && ((list && val[len] == ',') || val[len] == NUL))
  8452.         {
  8453.         val += len + (val[len] == ',');
  8454.         new_flags |= (1 << i);
  8455.         break;        /* check next item in val list */
  8456.         }
  8457.     }
  8458.     }
  8459.     if (flagp != NULL)
  8460.     *flagp = new_flags;
  8461.  
  8462.     return OK;
  8463. }
  8464.  
  8465. /*
  8466.  * Read the 'wildmode' option, fill wim_flags[].
  8467.  */
  8468.     static int
  8469. check_opt_wim()
  8470. {
  8471.     char_u    new_wim_flags[4];
  8472.     char_u    *p;
  8473.     int        i;
  8474.     int        idx = 0;
  8475.  
  8476.     for (i = 0; i < 4; ++i)
  8477.     new_wim_flags[i] = 0;
  8478.  
  8479.     for (p = p_wim; *p; ++p)
  8480.     {
  8481.     for (i = 0; ASCII_ISALPHA(p[i]); ++i)
  8482.         ;
  8483.     if (p[i] != NUL && p[i] != ',' && p[i] != ':')
  8484.         return FAIL;
  8485.     if (i == 7 && STRNCMP(p, "longest", 7) == 0)
  8486.         new_wim_flags[idx] |= WIM_LONGEST;
  8487.     else if (i == 4 && STRNCMP(p, "full", 4) == 0)
  8488.         new_wim_flags[idx] |= WIM_FULL;
  8489.     else if (i == 4 && STRNCMP(p, "list", 4) == 0)
  8490.         new_wim_flags[idx] |= WIM_LIST;
  8491.     else
  8492.         return FAIL;
  8493.     p += i;
  8494.     if (*p == NUL)
  8495.         break;
  8496.     if (*p == ',')
  8497.     {
  8498.         if (idx == 3)
  8499.         return FAIL;
  8500.         ++idx;
  8501.     }
  8502.     }
  8503.  
  8504.     /* fill remaining entries with last flag */
  8505.     while (idx < 3)
  8506.     {
  8507.     new_wim_flags[idx + 1] = new_wim_flags[idx];
  8508.     ++idx;
  8509.     }
  8510.  
  8511.     /* only when there are no errors, wim_flags[] is changed */
  8512.     for (i = 0; i < 4; ++i)
  8513.     wim_flags[i] = new_wim_flags[i];
  8514.     return OK;
  8515. }
  8516.  
  8517. /*
  8518.  * Check if backspacing over something is allowed.
  8519.  */
  8520.     int
  8521. can_bs(what)
  8522.     int        what;        /* BS_INDENT, BS_EOL or BS_START */
  8523. {
  8524.     switch (*p_bs)
  8525.     {
  8526.     case '2':    return TRUE;
  8527.     case '1':    return (what != BS_START);
  8528.     case '0':    return FALSE;
  8529.     }
  8530.     return vim_strchr(p_bs, what) != NULL;
  8531. }
  8532.  
  8533. /*
  8534.  * Save the current values of 'fileformat' and 'fileencoding', so that we know
  8535.  * the file must be considered changed when the value is different.
  8536.  */
  8537.     void
  8538. save_file_ff(buf)
  8539.     buf_T    *buf;
  8540. {
  8541.     buf->b_start_ffc = *buf->b_p_ff;
  8542. #ifdef FEAT_MBYTE
  8543.     vim_free(buf->b_start_fenc);
  8544.     buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
  8545. #endif
  8546. }
  8547.  
  8548. /*
  8549.  * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
  8550.  * from when editing started (save_file_ff() called).
  8551.  */
  8552.     int
  8553. file_ff_differs(buf)
  8554.     buf_T    *buf;
  8555. {
  8556.     if (buf->b_start_ffc != *buf->b_p_ff)
  8557.     return TRUE;
  8558. #ifdef FEAT_MBYTE
  8559.     if (buf->b_start_fenc == NULL)
  8560.     return (*buf->b_p_fenc != NUL);
  8561.     return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
  8562. #else
  8563.     return FALSE;
  8564. #endif
  8565. }
  8566.  
  8567. /*
  8568.  * return OK if "p" is a valid fileformat name, FAIL otherwise.
  8569.  */
  8570.     int
  8571. check_ff_value(p)
  8572.     char_u    *p;
  8573. {
  8574.     return check_opt_strings(p, p_ff_values, FALSE);
  8575. }
  8576.